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 Peacock Director of Information Research and Technology Rowman & Littlefield Publishing Group 4720 Boston Way Lanham, MD 20706 301-459-3366 x.5010 fax 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:

    
  1. Re: Non-repeating Random Numbers - CORRECTION (Dan Strong 2002)
  2. Re: Non-repeating Random Numbers - CORRECTION (Brian Fries 2002)
  3. Re: Non-repeating Random Numbers - CORRECTION (Stuart Tremain 2002)
  4. Re: Non-repeating Random Numbers - CORRECTION (Dan Strong 2002)
  5. Re: Non-repeating Random Numbers - CORRECTION (Stuart Tremain 2002)
  6. Re: Non-repeating Random Numbers - CORRECTION (Andrew Simpson 2002)
  7. Re: Non-repeating Random Numbers - CORRECTION (Andrew Simpson 2002)
  8. Re: Non-repeating Random Numbers (Andrew Simpson 2002)
  9. Re: Non-repeating Random Numbers - CORRECTION (Dan Strong 2002)
  10. Re: Non-repeating Random Numbers - CORRECTION (Dan Strong 2002)
  11. Re: Non-repeating Random Numbers (Dan Strong 2002)
  12. Re: Non-repeating Random Numbers (John Peacock 2002)
  13. Non-repeating Random Numbers (Dan Strong 2002)
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 Peacock Director of Information Research and Technology Rowman & Littlefield Publishing Group 4720 Boston Way Lanham, MD 20706 301-459-3366 x.5010 fax 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:

Re:quit command on NT (1997) RAM variables (1997) ooops...WebCatalog [FoundItems] Problem - LONG - (1997) Emailer (WebCat2) (1997) HMAC-MD5 hash -- what the... (2003) New public beta available (1997) [WebDNA] Conditional search (2009) Include from DB (2002) [shownext] and descending order (1997) Help ! Frustrating Problem (1999) eCommerce software pricing (1998) No. of items in shopping cart (2000) Webcat Hosting in London or UK (2003) Re[2]: How true is this? (1999) WebCat2 Append problem (B14Macacgi) (1997) Tea Room trouble (1997) View Source from cache (1997) suffix mapping for NT? (1997) 2.0 Info (1997) SMI or WebDNA Vets. please read (2004)