Re: Non-repeating Random Numbers
This WebDNA talk-list message is from 2002
It keeps the original formatting.
numero = 43036
interpreted = N
texte = Dan Strong wrote:> Generate 6 random numbers between 1 and 54:> > How do I simply and elegantly ensure that all six numbers are different? > By simply and elegantly I mean without resorting to any temp .dbs or > anything like that.>
That's not random, though. A true random number sequence can contain a very large run of identical values.What I think you want is to chose 6 unique values from between 1 and 54. Why don't you store the result in a text variable and check to see if the value you are looking for is already there? Remember to use a delimeter around each value so you don't match substrings. Something like this (NOT TESTED):[text]numbers=+[text][math]found=0[/math][loop start=1&end=20] [text]number=[math]ceil([RANDOM format=float]*(54))[/math][/text] [showif [numbers]!+[number]+] [text]numbers=[numbers]+[number]+[/text] [math]found=[found]+1[/math] [/showif] [showif [found]=6][break][/showif][/loop]then your [numbers] text variable contains all 6 unique values. Be aware that PRND's for most computers are really lousy.John-- John PeacockDirector of Information Research and TechnologyRowman & Littlefield Publishing Group4720 Boston WayLanham, MD 20706301-459-3366 x.5010fax 301-429-5747-------------------------------------------------------------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:
Dan Strong wrote:> Generate 6 random numbers between 1 and 54:> > How do I simply and elegantly ensure that all six numbers are different? > By simply and elegantly I mean without resorting to any temp .dbs or > anything like that.> That's not random, though. A true random number sequence can contain a very large run of identical values.What I think you want is to chose 6 unique values from between 1 and 54. Why don't you store the result in a text variable and check to see if the value you are looking for is already there? Remember to use a delimeter around each value so you don't match substrings. Something like this (NOT TESTED):[text]numbers=+[text][math]found=0[/math][loop start=1&end=20] [text]number=[math]ceil([RANDOM format=float]*(54))[/math][/text] [showif [numbers]!+[number]+] [text]numbers=[numbers]+[number]+[/text] [math]found=[found]+1[/math] [/showif] [showif [found]=6][break][/showif][/loop]then your [numbers] text variable contains all 6 unique values. Be aware that PRND's for most computers are really lousy.John-- John PeacockDirector of Information Research and TechnologyRowman & Littlefield Publishing Group4720 Boston WayLanham, MD 20706301-459-3366 x.5010fax 301-429-5747-------------------------------------------------------------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/
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:
HTML Editors (1997)
HELP WITH DATES (1997)
remotely add + sign (1997)
Cookies and WebCat?? (1999)
Can't load tmpl files (1997)
NT vs Mac (1997)
[WebDNA] TLS 1.2 and [tcpconnect] (2018)
REPOST: Large founditems loops (2000)
WebCat2b13MacPlugIn - [showif][search][/showif] (1997)
can WC render sites out? (1997)
[WebDNA] Mass email using WebDNA (2008)
shownext & math (1997)
Wrapping text (1998)
RE: WebCatalog NT beta 18 now available (1997)
Here we go again... was: DDEConnect not working (2006)
[WebDNA] Require no empty field (2010)
Post Limits (1998)
Just Testing (1997)
[WebDNA] Nested Searches (2013)
setting taxable to true (1997)