previous
|
start
|
next
Simulations
To generate a random
floating-point number
, note that the quantity
rand() * 1.0 / RAND_MAX
is a random floating-point value between 0 and 1.
The 1.0 ensures that the division is a floating-point number.
double rand_double(double a, double b) { return a + (b - a) * rand() * (1.0 / RAND_MAX);
previous
|
start
|
next