# 5. Converse Pseudorandom Number Generator

Converse provides three different Linear Congruential Random Number Generators.
Each random number stream has a cycle length of as opposed to
ANSI C standard's .
Also, each of the three random number streams can be split into a number of
per processor streams, so that the random number sequences can be computed
in parallel, and are reproducible. Furthermore, there is no implicit critical
section in the random number generator,and yet, this functionality is
thread-safe, because all the state information is stored in the structure
allocated by the programmer. Further, this state information is stored in a
first class object, and can be passed to other processors through messages.
This module of Converse is based on the public-domain
SPRNG^{5.1}
package developed
by Ashok Srinivasan^{5.2} at NCSA.

For minimal change to programs already using C functions rand(), srand(), and drand48(), Converse also maintains a “default” random number stream.

Interface to the Converse Pseudorandom Number Generator module is as follows:

typedef ... CrnStream;

State information for generating the next random number in the sequence.

void CrnInitStream(CrnStream *stream, int seed, int type)

Initializes the new random number stream stream
of type using seed. type can have values 0, 1, or 2
to represent three types of linear congruential random number generators.

int CrnInt(CrnStream *stream)

Returns an integer between 0 and corresponding to the next
random number in the sequence associated with stream.
Advances stream by one in the sequence.

double CrnDouble(CrnStream *stream)

Returns an double precision floating point number between 0 and 1
corresponding to the next
random number in the sequence associated with stream.
Advances stream by one in the sequence.

float CrnFloat(CrnStream *stream)

Returns a single precision floating point number between 0 and 1
corresponding to the next
random number in the sequence associated with stream.
Advances stream by one in the sequence.

void CrnSrand(int seed)

Specifies a different seed for the default random number stream.
Replaces srand().

int CrnRand(void)

Generate the next integer random number from the default random number
stream. Replaces rand().

double CrnDrand(void)

Generate the next double precision random number from the default random number
stream. Replaces drand48().