next up previous contents
Next: Planting a Seed Up: Randomization Previous: Randomization

The Random Function

In Darwin, the Rand function begins with a predefined seed and produces a pseudo-random sequence of numbers between $0\ldots 1$.

> Rand();
0.03219977
> Rand();
0.3408
> Rand();
0.7549
If we are to quit, and then restart a Darwin session, we would see that entering
> Rand();
0.03219977
> Rand();
0.3408
> Rand();
0.7549
produces the exact same sequence. This is a nice property which can be exploited when debugging programs that make use of randomization as it allows us to compare successive executions of our program on the same input values.



Gaston Gonnet
1998-09-15