Say we have an array of name and weight
Something like
Jane 5 John 3 Dane 0 Doe 1
If weight is 0, the name Dane should show up 1/10th of a time than if the weight is 1
The rest are proportional.
So name Jane will show up 5 more times than Doe
Maximum weight is 10
I am thinking of an efficient algorithm to pick names based on their weight.
The way I currently do is to just translate the weight into a very big array.
So Dane will have an entry. Jane will have 50 entries. And then I pick randomly where each entries have equal chance.
I am using PhP.
I wonder if there is a more efficient way.