Balancing randomness

This WebDNA talk-list message is from

2000


It keeps the original formatting.
numero = 27932
interpreted = N
texte = There was a recent thread on the randomness (or lack thereof) of sdir=ra. I had to put something together today to ensure that five randomly selected items got equal play (to get more of a shuffle sort) and I thought the code may be of use to some : )When I just used a [random] tag to generate numbers from 1 to 5 (creating 1000 numbers total for these examples), I got a typical bell curve most strongly weighted on the 3:[math show=f]total1=0,total2=0,total3=0,total4=0,total5=0[/math] [loop start=1&end=1000] [math]pick=[format .0f][math]pick=(([random]/100)*4)+1[/math][/format][/math] [math show=f]total[pick]=[interpret][total[pick]][/interpret]+1[/math] [/loop]

[loop start=1&end=5] [index] = [interpret][total[index]][/interpret] ([math][interpret][total[index]][/interpret]/10[/math]%)
[/loop]1 = 153 (15.3%) 2 = 227 (22.7%) 3 = 254 (25.4%) 4 = 233 (23.3%) 5 = 133 (13.3%)-----------------------------So I set up a separate database to serve as a lookup for the numbers ...prizeShuffle.db: ref num count 1 1 3 2 1 3 4 4 5 5 2... and then stepped through each number in turn. Each time after using them all, they're given another pass through, this time randomly swapping their positions and resetting the count to 1.[math show=f]total1=0,total2=0,total3=0,total4=0,total5=0[/math] [loop start=1&end=1000] [math show=f]theCount=[lookup db=prizeShuffle.db&value=count&lookInField=ref&returnField=num¬Found=1][ /math] [math]pickNum=[lookup db=prizeShuffle.db&value=[theCount]&lookInField=ref&returnField=num¬Foun d=1][/math] [math show=f]total[pickNum]=[interpret][total[pickNum]][/interpret]+1[/math][showif [math]theCount=[theCount]+1[/math]=6] [replace db=prizeShuffle.db&eqRefData=count]num=1[/replace] [loop start=1&end=5] [math show=f]swap=[format .0f][math]pick=(([random]/100)*4)+1[/math][/format][/math] [math show=f]temp=[lookup db=prizeShuffle.db&value=[index]&lookInField=ref&returnField=num¬Found=1 ][/math] [replace db=prizeShuffle.db&eqRefData=[index]]num=[lookup db=prizeShuffle.db&value=[swap]&lookInField=ref&returnField=num¬Found=1] [/replace] [replace db=prizeShuffle.db&eqRefData=[swap]]num=[temp][/replace] [/loop] [/showif][showif [theCount]!6] [replace db=prizeShuffle.db&eqRefData=count]num=[theCount][/replace] [/showif][/loop]

[loop start=1&end=5] [index] = [interpret][total[index]][/interpret] ([math][interpret][total[index]][/interpret]/10[/math]%)
[/loop]1 = 200 (20%) 2 = 200 (20%) 3 = 200 (20%) 4 = 200 (20%) 5 = 200 (20%)Whazoo! : ) Rob Marquardt Designer/Resident Wirehead Toast Design800 Washington Avenue North Minneapolis MN 55401 612.330.9863 v 612.321.9424 f www.toastdesign.com ------------------------------------------------------------- Brought to you by CommuniGate Pro - The Buzz Word Compliant Messaging Server. To end your Mail problems go to .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 Associated Messages, from the most recent to the oldest:

    
  1. Re: Balancing randomness (Rob Marquardt 2000)
  2. Re: Balancing randomness (Peter Ostry 2000)
  3. Re: SOLUTION.... Re: Balancing randomness (Rob Marquardt 2000)
  4. Re: Balancing randomness (Christer Olsson 2000)
  5. Re: SOLUTION.... Re: Balancing randomness (Kenneth Grome 2000)
  6. Re: SOLUTION.... Re: Balancing randomness (Rob Marquardt 2000)
  7. SOLUTION.... Re: Balancing randomness (Joseph D'Andrea 2000)
  8. Re[2]: Balancing randomness (Kenneth Grome 2000)
  9. Re: Balancing randomness (Joseph D'Andrea 2000)
  10. Re: Balancing randomness (John Butler 2000)
  11. Re[2]: Balancing randomness (Joseph D'Andrea 2000)
  12. Re: Balancing randomness (Miguel Castaneda 2000)
  13. Re: Balancing randomness (Rob Marquardt 2000)
  14. Re: Balancing randomness (Joseph D'Andrea 2000)
  15. Re[2]: Balancing randomness (jpeacock@univpress.com 2000)
  16. Re[2]: Balancing randomness (jpeacock@univpress.com 2000)
  17. Re: Balancing randomness (Peter Ostry 2000)
  18. Re: Balancing randomness (Rob Marquardt 2000)
  19. Re: Balancing randomness (Joseph D'Andrea 2000)
  20. Re: Balancing randomness (jpeacock@univpress.com 2000)
  21. Balancing randomness (Rob Marquardt 2000)
There was a recent thread on the randomness (or lack thereof) of sdir=ra. I had to put something together today to ensure that five randomly selected items got equal play (to get more of a shuffle sort) and I thought the code may be of use to some : )When I just used a [random] tag to generate numbers from 1 to 5 (creating 1000 numbers total for these examples), I got a typical bell curve most strongly weighted on the 3:[math show=f]total1=0,total2=0,total3=0,total4=0,total5=0[/math] [loop start=1&end=1000] [math]pick=[format .0f][math]pick=(([random]/100)*4)+1[/math][/format][/math] [math show=f]total[pick]=[interpret][total[pick]][/interpret]+1[/math] [/loop]

[loop start=1&end=5] [index] = [interpret][total[index]][/interpret] ([math][interpret][total[index]][/interpret]/10[/math]%)
[/loop]1 = 153 (15.3%) 2 = 227 (22.7%) 3 = 254 (25.4%) 4 = 233 (23.3%) 5 = 133 (13.3%)-----------------------------So I set up a separate database to serve as a lookup for the numbers ...prizeShuffle.db: ref num count 1 1 3 2 1 3 4 4 5 5 2... and then stepped through each number in turn. Each time after using them all, they're given another pass through, this time randomly swapping their positions and resetting the count to 1.[math show=f]total1=0,total2=0,total3=0,total4=0,total5=0[/math] [loop start=1&end=1000] [math show=f]theCount=[lookup db=prizeShuffle.db&value=count&lookInField=ref&returnField=num¬Found=1][ /math] [math]pickNum=[lookup db=prizeShuffle.db&value=[theCount]&lookInField=ref&returnField=num¬Foun d=1][/math] [math show=f]total[pickNum]=[interpret][total[pickNum]][/interpret]+1[/math][showif [math]theCount=[theCount]+1[/math]=6] [replace db=prizeShuffle.db&eqRefData=count]num=1[/replace] [loop start=1&end=5] [math show=f]swap=[format .0f][math]pick=(([random]/100)*4)+1[/math][/format][/math] [math show=f]temp=[lookup db=prizeShuffle.db&value=[index]&lookInField=ref&returnField=num¬Found=1 ][/math] [replace db=prizeShuffle.db&eqRefData=[index]]num=[lookup db=prizeShuffle.db&value=[swap]&lookInField=ref&returnField=num¬Found=1] [/replace] [replace db=prizeShuffle.db&eqRefData=[swap]]num=[temp][/replace] [/loop] [/showif][showif [theCount]!6] [replace db=prizeShuffle.db&eqRefData=count]num=[theCount][/replace] [/showif][/loop]

[loop start=1&end=5] [index] = [interpret][total[index]][/interpret] ([math][interpret][total[index]][/interpret]/10[/math]%)
[/loop]1 = 200 (20%) 2 = 200 (20%) 3 = 200 (20%) 4 = 200 (20%) 5 = 200 (20%)Whazoo! : ) Rob Marquardt Designer/Resident Wirehead Toast Design800 Washington Avenue North Minneapolis MN 55401 612.330.9863 v 612.321.9424 f www.toastdesign.com ------------------------------------------------------------- Brought to you by CommuniGate Pro - The Buzz Word Compliant Messaging Server. To end your Mail problems go to .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 Rob Marquardt

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:

WebCat2 - storing unformatted date data? (1997) Search design (1997) [WebDNA] bots continually create shoppingcart files (2018) [BULK] Fwd: [WebDNA] [BULK] WebDNA discovery in the Console - [having many crashes] (2011) using showpage and showcart commands (1996) WebCat2final1 crashes (1997) add to cart within a page? (1997) Help! (1999) Extended [ConvertChars] (1997) NT [delete] - duh nevermind. (1998) RE: AccountAuthorizer doesn't seem to work (1997) Authenticate (1997) [WebDNA] timestamp conversion (2011) Fun with dates (1997) Auto Unsubscribe (2000) WebDNA-Talk Digests (1997) Anyone using Verisign's Payflow Link for payment processing? (2000) Error with [applescript] (1999) different ship dates and shopping carts -- how to? (1997) any suggestions for creating a multi-lingual site? (1999)