Generate random number from an arbitrary weighted list
- by Fernando
Here's what I need to do, I'll be doing this both in PHP and JavaScript.
I have a list of numbers that will range from 1 to 300-500 (I haven't set the limit yet). I will be running a drawing were 10 numbers will be picked at random from the given range.
Here's the tricky part: I want some numbers to be less likely to be drawn up. A small set of those 300-500 will be flagged as "lucky numbers".
For example, out of 100 drawings, most numbers have equal chances of being drawn, except for a few, that will only be picked once every 30-50 drawings.
Basically I need to artificially set the probability of certain numbers to be picked while maintaining an even distribution with the rest of the numbers.
The only similar thing I've found so far is this question: Generate A Weighted Random Number, the problem being that my spec has considerably more numbers (up to 500) so the weights would get very small and supposedly this could be a problem with that solution (Rejection Sampling). I'm still trying it, though, but I wonder if there other solutions.
Math is not my thing so I appreciate any input. Thanks.