Go to the first, previous, next, last section, table of contents.


BSD Random Number Functions

This section describes a set of random number generation functions that are derived from BSD. There is no advantage to using these functions with the GNU C library; we support them for BSD compatibility only.

The prototypes for these functions are in `stdlib.h'.

Function: long int random ()
This function returns the next pseudo-random number in the sequence. The range of values returned is from 0 to RAND_MAX.

Function: void srandom (unsigned int seed)
The srandom function sets the seed for the current random number state based on the integer seed. If you supply a seed value of 1, this will cause random to reproduce the default set of random numbers.

To produce truly random numbers (not just pseudo-random), do srandom (time (0)).

Function: void * initstate (unsigned int seed, void *state, size_t size)
The initstate function is used to initialize the random number generator state. The argument state is an array of size bytes, used to hold the state information. The size must be at least 8 bytes, and optimal sizes are 8, 16, 32, 64, 128, and 256. The bigger the state array, the better.

The return value is the previous value of the state information array. You can use this value later as an argument to setstate to restore that state.

Function: void * setstate (void *state)
The setstate function restores the random number state information state. The argument must have been the result of a previous call to initstate or setstate.

The return value is the previous value of the state information array. You can use thise value later as an argument to setstate to restore that state.


Go to the first, previous, next, last section, table of contents.