Here we will engineer a random number generator that has a distribution that favors low values. You can use it to prefer items at the beginning of a list. To decrease the odds of something being selected, move that item down the list. You have a few options for how you want to move the item down the list. Lets review the random variable transformation first.
By applying the following function to a uniform random variable between 0 and 1:
index = Int(l*(1-r^(0.5)) # l=length, r=uniform random var between 0 and 1
You get a cool distribution that drastically reduces the odds of a larger index
p(0)=0.09751
p(1)=0.09246
p(2)=0.08769
p(3)=0.08211
p(4)=0.07636
p(5)=0.07325
p(6)=0.06772
p(7)=0.06309
p(8)=0.05813
p(9)=0.05274
p(10)=0.04808
p(11)=0.04205
p(12)=0.03691
p(13)=0.03268
p(14)=0.02708
p(15)=0.02292
p(16)=0.01727
p(17)=0.01211
p(18)=0.00736
p(19)=0.00249
Here is the distribution for a list of size 2
0.75139
0.24862
Size 3
0.55699
0.33306
0.10996
Size 4
0.43916
0.31018
0.18836
0.06231
Now lets discuss the two options for moving the items down the list. I tested two:
I created a simulation to pick from a list and examine the standard deviation of the count that each item was selected. The lower the standard deviation the better. For example, 1 simulation for a list of 10 items where 50 selections where made created the spread:
{"a"=>5, "b"=>5, "c"=>6, "d"=>5, "e"=>4, "f"=>4, "g"=>5, "h"=>5, "i"=>6, "j"=>5}
The Standard Devation for this simulation wa
answered 2009-10-20T18:37:55.083