P
Peter Oliphant
I would like to be able to create a random number generator that produces
evenly distributed random numbers up to given number.
For example, I would like to pick a random number less than 100000, or
between 0 and 99999 (inclusive).
Further, the I want the range to be a variable. Concretely, I would like to
create the following method:
unsigned long Random( unsigned long num )
{
// return a uniformly distributed random number R in the range: 0 <=
R <= (num-1)
}
I also would like this to be as executionally fast as possible. I have been
trying to to this using rand() as my basis, but everything I try ends up
with one problem or another (e.g., outside of range, not evenly distributed,
execution too long).
I'm using VS C++ 2005 Express Edition (managed /clr pure), and was hoping
that there is a better alternative to rand( ) as the basis of random
numbers, since this always generates an evenly distributed number from 0 to
RAND_MAX (0x7fff), which is not easily adapted to the task I've described
above...
If there is a cheap third-party class I could buy to do this, I'd be
interested in that too...
Thanx in advance for responses!
evenly distributed random numbers up to given number.
For example, I would like to pick a random number less than 100000, or
between 0 and 99999 (inclusive).
Further, the I want the range to be a variable. Concretely, I would like to
create the following method:
unsigned long Random( unsigned long num )
{
// return a uniformly distributed random number R in the range: 0 <=
R <= (num-1)
}
I also would like this to be as executionally fast as possible. I have been
trying to to this using rand() as my basis, but everything I try ends up
with one problem or another (e.g., outside of range, not evenly distributed,
execution too long).
I'm using VS C++ 2005 Express Edition (managed /clr pure), and was hoping
that there is a better alternative to rand( ) as the basis of random
numbers, since this always generates an evenly distributed number from 0 to
RAND_MAX (0x7fff), which is not easily adapted to the task I've described
above...
If there is a cheap third-party class I could buy to do this, I'd be
interested in that too...
Thanx in advance for responses!