next up previous contents index
Next: max,min Up: RandomNumberGenerator Previous: apply   Contents   Index


generator


Usage

for n in r repeat { ...}
for n in generator r repeat { ...}


Signature

generator: % $\to$ Generator MachineInteger


Parameter Type Description
r % a pseudo-random number generator


Description

This functions allows a for-loop that generates infinitely many pseudo-random numbers.


Example

The following code computes the number of tries it takes for a random generator to generate a multiple of 10:
multiple10():MachineInteger == {
    r := randomGenerator();
    for n in r for tries in 1.. repeat {
		zero?(n rem 10) => return tries;
    }
    never;
}



Manuel Bronstein 2004-06-28