OK, here is my idea:
Let's say you have an array of elements (a,b,c,d)
, and you cannot accidentally select one of them. Doing rand(1,4)
to get an index of random elements would mean that all elements have an equal chance of appearing. (25%)
Now suppose we take this array: (a,b,c,d,d)
.
Here we still have 4 elements, but not each of them has an equal chance of appearing.
Or take this array:
(1,2,3,...,97,97,97,98,98,98,99,99,99,100,100,100,100)
Hint: Thus, you not only reject the random number generation algorithm, but actually set the desired probability of each of them (or a range of numbers).
So how would I do this:
If you want numbers from 1 to 100 (with higher numbers appearing more often, get a random number from 1 to 1000 and associate it with a wider range. For example,
rand = 800-1000 => rand/10 (80->100) rand = 600-800 => rand/9 (66->88) ...
Or something like that. (You can use any mathematical operation that you represent, modulo or something else ... and play with your algorithm). I hope you understand my idea.
Good luck! :-)