Re: Non-repeating Random Numbers - CORRECTION

This WebDNA talk-list message is from

2002


It keeps the original formatting.
numero = 43067
interpreted = N
texte = Dan -There's one important item you removed from John's proposal, and it will cause poor random number distribution if you don't fix it...You need to include delimiters surrounding each number you stick into your unique_numbers text variable, and include those delimiters in your contains test. The way your code is written below, the numbers 1 and 4 will be rejected if the number 41 has already been chosen, because 41 contains 1 and 4. Statistically, you will have a significant shortage of 1-digit numbers.Your code uses a space as a delimiter, which is fine, but you need to initialize unique_numbers with a leading space. John used + as his delimiter, my preference is usually to use _ or |, but it's really up to you.Simply, to fix this problem in your code and continue using the space delimiter, I would change two lines:[text show=f]unique_numbers= [/text] ^ note the space characterand[hideif [unique_numbers]^ [random_number] ] ^ ^ note the space characters- brian At 3:57 PM 9/1/02, Dan Strong wrote: >Andrew, > >I don't really want to search a .db that's why I went the route I >did...but I'm sure your code works fine... > >Seems I spoke too soon..previous code was showing duplicate #s >(read: not working as intended) so I altered the code slightly from >before, and it appears to work. For anyone who's interested here is >working code (Andrew (and any 'grown-ups')can ignore this... ;) > >[!] -- Randomly 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] >[hideif [unique_numbers]^[random_number]] >[text show=f]unique_numbers=[unique_numbers][random_number] [/text] >[math show=f]found=[found]+1[/math] >[/hideif] >[showif [found]=6][break][/showif] >[/loop] >[unique_numbers] > >-Dan >------------------------------------------- >http://www.StrongGraphicDesign.com >(208) 319-0137 | Toll-free p/f 877-561-1656 > > > >On Mon, 2 Sep 2002 11:08:32 > Andrew Simpson wrote: >>whats wrong with : >> >>[search >>db=/db/54numbersfrom1-54.db&neNUMBERdatarq=[BLANK]&raNUMBERsort=1&NUMBERtype >>=NUM&max=6] >> [founditems][number]
[/founditems] >>[/search] >> >> >>----- Original Message ----- >>From: Dan Strong >>To: WebCatalog Talk >>Sent: Monday, September 02, 2002 10:46 AM >>Subject: Re: Non-repeating Random Numbers - CORRECTION >> >>>whoops... >>>[showif [found]=5][break][/showif] >>>should say 6, not 5... corrected code below: >>> >>>[!] --- 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]=6][break][/showif] >>>[/loop] >>>[unique_numbers] >>> >>>-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/ >> >> >>------------------------------------------------------------- >>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/ > > >------------------------------------------------------------- >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/ ------------------------------------------------------------- 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 - CORRECTION (Dan Strong 2002)
  9. Re: Non-repeating Random Numbers - CORRECTION (Dan Strong 2002)
Dan -There's one important item you removed from John's proposal, and it will cause poor random number distribution if you don't fix it...You need to include delimiters surrounding each number you stick into your unique_numbers text variable, and include those delimiters in your contains test. The way your code is written below, the numbers 1 and 4 will be rejected if the number 41 has already been chosen, because 41 contains 1 and 4. Statistically, you will have a significant shortage of 1-digit numbers.Your code uses a space as a delimiter, which is fine, but you need to initialize unique_numbers with a leading space. John used + as his delimiter, my preference is usually to use _ or |, but it's really up to you.Simply, to fix this problem in your code and continue using the space delimiter, I would change two lines:[text show=f]unique_numbers= [/text] ^ note the space characterand[hideif [unique_numbers]^ [random_number] ] ^ ^ note the space characters- brian At 3:57 PM 9/1/02, Dan Strong wrote: >Andrew, > >I don't really want to search a .db that's why I went the route I >did...but I'm sure your code works fine... > >Seems I spoke too soon..previous code was showing duplicate #s >(read: not working as intended) so I altered the code slightly from >before, and it appears to work. For anyone who's interested here is >working code (Andrew (and any 'grown-ups')can ignore this... ;) > >[!] -- Randomly 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] >[hideif [unique_numbers]^[random_number]] >[text show=f]unique_numbers=[unique_numbers][random_number] [/text] >[math show=f]found=[found]+1[/math] >[/hideif] >[showif [found]=6][break][/showif] >[/loop] >[unique_numbers] > >-Dan >------------------------------------------- >http://www.StrongGraphicDesign.com >(208) 319-0137 | Toll-free p/f 877-561-1656 > > > >On Mon, 2 Sep 2002 11:08:32 > Andrew Simpson wrote: >>whats wrong with : >> >>[search >>db=/db/54numbersfrom1-54.db&neNUMBERdatarq=[BLANK]&raNUMBERsort=1&NUMBERtype >>=NUM&max=6] >> [founditems][number]
[/founditems] >>[/search] >> >> >>----- Original Message ----- >>From: Dan Strong >>To: WebCatalog Talk >>Sent: Monday, September 02, 2002 10:46 AM >>Subject: Re: Non-repeating Random Numbers - CORRECTION >> >>>whoops... >>>[showif [found]=5][break][/showif] >>>should say 6, not 5... corrected code below: >>> >>>[!] --- 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]=6][break][/showif] >>>[/loop] >>>[unique_numbers] >>> >>>-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/ >> >> >>------------------------------------------------------------- >>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/ > > >------------------------------------------------------------- >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/ ------------------------------------------------------------- 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/ Brian Fries

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:

WebCatalog for guestbook ? (1997) insecuretextvars preference doesn't work (2000) [no_cache]?! (2000) WebMerchant when CC network is down (1998) Multiple download orders of the same product? (1997) Shopping Cart Limits? (1998) BUG REPORT: numeric ge, le, gr & ls comparisons don't work ... (1999) The beginning (1997) relogin same user? (1998) Online magazine- monthly updates and such (1999) price on detail, but not shoppingcart (1997) contextual shownext (1998) OT: Amazon Patents (2000) did I miss anything (1997) Public beta 4 of WebCatalog 4.0 is now available (2000) all records returned. (1997) Exclamation point (1997) Separate SSL Server (1997) Google Web Accelerator (2005) Opinion: [input] should be called [output] ... (1997)