Re: Efficient way to gen a random number in a particular range?
- From: Scott Contini <the_great_contini@xxxxxxxxx>
- Date: Mon, 10 Aug 2009 20:21:40 -0700 (PDT)
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
.
- Follow-Ups:
- References:
- Efficient way to gen a random number in a particular range?
- From: Dave -Turner
- Efficient way to gen a random number in a particular range?
- Prev by Date: Efficient way to gen a random number in a particular range?
- Next by Date: Re: Efficient way to gen a random number in a particular range?
- Previous by thread: Efficient way to gen a random number in a particular range?
- Next by thread: Re: Efficient way to gen a random number in a particular range?
- Index(es):