Re: Non-repeating Random Numbers
This WebDNA talk-list message is from 2002
It keeps the original formatting.
numero = 43039
interpreted = N
texte = John,>
>That's not random, though. A true random number sequence >can contain a very large run of identical values.>Point taken :)Ok, this appears to work:[!] --- Generate 6 unique numbers between 1 and 54 --- [/!][text show=f]unique_numbers= [/text][math show=f]found=0[/math][loop start=1&end=20][text show=f]random_number=[math]ceil([RANDOM format=float]*(54))[/math][/text][showif [unique_numbers]! [random_number] ][text show=f]unique_numbers=[unique_numbers][random_number] [/text][math show=f]found=[found]+1[/math][/showif][showif [found]=5][break][/showif][/loop][unique_numbers]I changed a few thing so I could understand the logic better, namely:1) I renamed the variables to something more literal that I could wrap my mind around, and2) I used
(The actual space bar) as a delimiter instead of '+' because '+' was confusing me into thinking I was doing math at first and also the display of the final numbers is cleaner with . Seems to work ok for the time being, but if I want to manhandle the [unique_numbers] variable later (with [grep] or whatever) I'll probably have to use a more tangible delimiter...don't really know yet and I'm just rambling..One question: regarding [loop start=1&end=20]:Theoretically, the process could loop 20 times in a row and not generate unique numbers (basically, end=20 could occur before [found]=5) and if this happened then the loop would stop without generating 6 numbers, right? Should I increase this limit to, oh, say 1000 or something to avoid this (unlikely) scenario?Thanks John!-Dan-------------------------------------------http://www.StrongGraphicDesign.com(208) 319-0137 | Toll-free p/f 877-561-1656-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/
Associated Messages, from the most recent to the oldest:
John,>>That's not random, though. A true random number sequence >can contain a very large run of identical values.>Point taken :)Ok, this appears to work:[!] --- Generate 6 unique numbers between 1 and 54 --- [/!][text show=f]unique_numbers= [/text][math show=f]found=0[/math][loop start=1&end=20][text show=f]random_number=[math]ceil([RANDOM format=float]*(54))[/math][/text][showif [unique_numbers]! [random_number] ][text show=f]unique_numbers=[unique_numbers][random_number] [/text][math show=f]found=[found]+1[/math][/showif][showif [found]=5][break][/showif][/loop][unique_numbers]I changed a few thing so I could understand the logic better, namely:1) I renamed the variables to something more literal that I could wrap my mind around, and2) I used (The actual space bar) as a delimiter instead of '+' because '+' was confusing me into thinking I was doing math at first and also the display of the final numbers is cleaner with . Seems to work ok for the time being, but if I want to manhandle the [unique_numbers] variable later (with [grep] or whatever) I'll probably have to use a more tangible delimiter...don't really know yet and I'm just rambling..One question: regarding [loop start=1&end=20]:Theoretically, the process could loop 20 times in a row and not generate unique numbers (basically, end=20 could occur before [found]=5) and if this happened then the loop would stop without generating 6 numbers, right? Should I increase this limit to, oh, say 1000 or something to avoid this (unlikely) scenario?Thanks John!-Dan-------------------------------------------http://www.StrongGraphicDesign.com(208) 319-0137 | Toll-free p/f 877-561-1656-------------------------------------------------------------This message is sent to you because you are subscribed to the mailing list .To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/
Dan Strong
DOWNLOAD WEBDNA NOW!
Top Articles:
Talk List
The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...
Related Readings:
Calculating a total (2000)
WebCatalog 2.0.1 NT beta 1 released (1997)
Server slowing down. (1997)
shipcost (1997)
Multiple catalog databases and showcart (1997)
[WebDNA] WebDNA is not parsing CSS file (2010)
WebTen and WebCat (1997)
Firesite and [referrer] atg broke (1997)
Goofy Date Sorting (1998)
Signal Raised Error (1997)
convert characters (2003)
test (2000)
form data submission gets truncated (1997)
Text data with spaces in them... (1997)
Include a big block of text (1997)
Sort Issue? (2000)
Robert Minor duplicate mail (1997)
price on detail, but not shoppingcart (1997)
About Include (2001)
Exclamation point (1997)