Re: Efficient way to gen a random number in a particular range?



On Aug 11, 12:22 pm, "Dave -Turner" <ad...@xxxxxxxxx> wrote:
so I have a 32bit PRNG, but let's say I just want to create random numbers
in a particular range, say 10 - 50 ... what would be a good approach to
that??? Obviously i don't want to call it thousands/millions of times until
I get a number that falls in range


do {
x = prng() % 64;
while (x >= 41);
/* now x is between 0 and 40 */
output x + 10;

Scott
.