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'.
0
to RAND_MAX
.
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))
.
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.
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.