strickdd
asked on
Random Number from 0 to X
I need a random number generator that will give me a different number each time it is executed. The purpose of this is to insert random FLOAT numbers into an array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
one addition:
The rand() function wll provide the same sequence of random integer values [0...RANDMAX] whenever your application restarts.
Use srand((unisnged int) time());
to intialize ('seed') the random number sequence.
Cheers,
Sebastian
The rand() function wll provide the same sequence of random integer values [0...RANDMAX] whenever your application restarts.
Use srand((unisnged int) time());
to intialize ('seed') the random number sequence.
Cheers,
Sebastian
//** a = [0...1[
double a = (double)(rand()%RAND_MAX) / RAND_MAX
will generate pseudo random floating point values between 0 and 0.999...
There are better random number generators than the standard c implentation.
Get back if you have higher demands on the randomness.
Cheers,
Sebastian