I'm having trouble generating random numbers that do not follow a discrete uniform distribution.
So for example, say I have 5 numbers (to keep it simple), a probability of number k being generated would be k/15. (k = 1 to 5)
My idea is to generate a random number j using rand(), and if this number j is:
1 => then number 1 is generated
2 or 3 => num 2
4 or 5 or 6 => num 3
7 or 8 or 9 or 10 => num 4
11 or 12 or 13 or 14 or 15 => num 5
Now scale this to generating 1-10, 1-100, 1-1000. Does this work the way I intend it to? I've constructed a loop that pretty much does this every time a number needs to be generated, I think it's probably inefficient since it goes up until it finds the j number generated in one of the ranges... What could be a better way to do this?
EDIT: or maybe create an array once with the proper numbers and then pull out with rand() better solution?