-> Click here to learn how to get live help <-
NAMErandom, srandom, initstate, setstate - random number generator
#include <stdlib.h> long int random(void); void srandom(unsigned int seed); char *initstate(unsigned int seed, char *state, size_t n); char *setstate(char *state);
DESCRIPTIONThe fBrandom()fP function uses a non-linear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers in the range from 0 to fBRAND_MAXfR. The period of this random number generator is very large, approximately 16*((2**31)-1).
The fBsrandom()fP function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by fBrandom()fP. These sequences are repeatable by calling fBsrandom()fP with the same seed value. If no seed value is provided, the fBrandom()fP function is automatically seeded with a value of 1.
The fBinitstate()fP function allows a state array fIstatefP to be initialized for use by fBrandom()fP. The size of the state array fInfP is used by fBinitstate()fP to decide how sophisticated a random number generator it should use (em the larger the state array, the better the random numbers will be. fIseedfP is the seed for the initialization, which specifies a starting point for the random number sequence, and provides for restarting at the same point.
The fBsetstate()fP function changes the state array used by the fBrandom()fP function. The state array fIstatefP is used for random number generation until the next call to fBinitstate()fP or fBsetstate()fP. fIstatefP must first have been initialized using fBinitstate()fP or be the result of a previous call of fBsetstate()fP.
RETURN VALUEThe fBrandom()fP function returns a value between 0 and RAND_MAX. The fBsrandom()fP function returns no value. The fBinitstate()fP and fBsetstate()fP functions return a pointer to the previous state array, or NULL on error.
NOTESCurrent "optimal" values for the size of the state array fInfP are 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to the nearest known amount. Using less than 8 bytes will cause an error.
CONFORMING TOBSD 4.3
SEE ALSOrand(3), srand(3)