initstate

Initializes random number generators.

Format

#include  <stdlib.h>

char *initstate  (unsigned int seed, char *state,
                 int size);

Arguments

seed
An initial seed value.
state
Pointer to an array of state information.
size
The size of the state information array.

Description

This function initializes random number generators. It lets you initialize for future use, a state array passed as an argument. The size in bytes of the state array is used by the initstate function to decide how sophisticated a random number generator to use; the larger the state array, the more random the numbers.

Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. Amounts less than 8 bytes generate an error, while other amounts are rounded down to the nearest known value.

The seed argument specifies a starting point for the random number sequence and provides for restarting at the same point. The initstate function returns a pointer to the previous state information array.

Once you initialize a state, the setstate function allows rapid switching between states. The array defined by the state argument is used for further random number generation until the initstate function is called or the setstate function is called again. The setstate function returns a pointer to the previous state array.

After initialization, you can restart a state array at a different point in one of two ways:

See also setstate, and srandom, in this section.

Return Values
A pointer to the previous state array information. 
Indicates an error. Call made with less than 8 bytes of state information. Further specified in the global errno. 


Previous Page | Next Page | Table of Contents | Index