Re: random prob
This WebDNA talk-list message is from 2003
It keeps the original formatting.
numero = 50398
interpreted = N
texte = Ron Ceballos wrote:> i'm having a bit of trouble with this code -- for the life of me i can't get> it to truly give me unique, random numbers, it always duplicates 2 values> First things first, the following sequence of numbers is perfectly legitimate in a random sequence: ...1,2,3,4,5,5,5,5,6,7,8....Truly random includes the possibility of both finite localized patterns, as well as duplicates. You need to decide what you are really looking for; it sounds like what you want is non-repeating random numbers in a certain range.Secondly, performing [math] in general and especially [math ceil()] on random numbers will cause the resulting numbers to become non-random (i.e. the numbers 8 through 14 will all map to 2 when divided by 7 and then [math ceil()]'d). If you have to do it this way, use [math floor([random format=float]*[x])] [!]where x is the max number you want to get[\!]since that will be a better distribution of numbers.A better technique is to take [random] in a [loop] and throw out any number out of the range you are interested in (as long as your range is < 100), or in your case any repeated digit.Lastly, I really question the programming technique of storing numerical values in text variables. Show of hands, how many people have actually written templates where you ran out of math variables (that's 150 individually named variables)?John-- John PeacockDirector of Information Research and TechnologyRowman & Littlefield Publishing Group4501 Forbes BoulevardSuite HLanham, MD 20706301-459-3366 x.5010fax 301-429-5748-------------------------------------------------------------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://webdna.smithmicro.com/
Associated Messages, from the most recent to the oldest:
Ron Ceballos wrote:> i'm having a bit of trouble with this code -- for the life of me i can't get> it to truly give me unique, random numbers, it always duplicates 2 values> First things first, the following sequence of numbers is perfectly legitimate in a random sequence: ...1,2,3,4,5,5,5,5,6,7,8....Truly random includes the possibility of both finite localized patterns, as well as duplicates. You need to decide what you are really looking for; it sounds like what you want is non-repeating random numbers in a certain range.Secondly, performing [math] in general and especially [math ceil()] on random numbers will cause the resulting numbers to become non-random (i.e. the numbers 8 through 14 will all map to 2 when divided by 7 and then [math ceil()]'d). If you have to do it this way, use [math floor([random format=float]*[x])] [!]where x is the max number you want to get[\!]since that will be a better distribution of numbers.A better technique is to take [random] in a [loop] and throw out any number out of the range you are interested in (as long as your range is < 100), or in your case any repeated digit.Lastly, I really question the programming technique of storing numerical values in text variables. Show of hands, how many people have actually written templates where you ran out of math variables (that's 150 individually named variables)?John-- John PeacockDirector of Information Research and TechnologyRowman & Littlefield Publishing Group4501 Forbes BoulevardSuite HLanham, MD 20706301-459-3366 x.5010fax 301-429-5748-------------------------------------------------------------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://webdna.smithmicro.com/
John Peacock
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:
authenticating a second user (1997)
shipcost (1997)
[SHOWIF] (1997)
Reversed words (1997)
[OT] Who's got a cool link (2002)
'does not contain' operator needed ... (1997)
Hiding usernames and passwords in URL (1998)
WebCat2b12 CGI Mac - [shownext] problem (1997)
I want a 404 (2005)
suffix mapping for NT? (1997)
Formatting ModDate (2000)
(1997)
Sorting (1998)
Using files in an Email broadcast (1999)
Formatting ModDate (2000)
Nested tags count question (1997)
Webcatalog Conference? (1998)
Size of WebDNA (version) market??? (2004)
method of payment (1997)
Multiple catalog databases and showcart (1997)