VMS Help
CRTL, random
*Conan The Librarian
|
Generates pseudorandom numbers in a more random sequence.
Format
#include <stdlib.h>
long int random (void);
The random function is a random-number generator that has
virtually the same calling sequence and initialization properties
as the rand function, but produces sequences that are more
random. The low 12 bits generated by rand go through a cyclic
pattern. All bits generated by random are usable. For example,
random() &1 produces a random binary value.
The random function uses a nonlinear, additive-feedback, random-
number generator employing a default state-array size of 31
integers to return successive pseudorandom numbers in the range
from 0 to 231 - 1. The period of this random-number generator is
approximately 16*(231 -1). The size of the state array determines
the period of the random-number generator. Increasing the state
array size increases the period.
With a full 256 bytes of state information, the period of the
random-number generator is greater than 269, and is sufficient
for most purposes.
Like the rand function, the random function produces by default a
sequence of numbers that you can duplicate by calling the srandom
function with a value of 1 as the seed. The srandom function,
unlike the srand function, does not return the old seed because
the amount of state information used is more than a single word.
See also rand, srand, srandom, setstate, and initstate.
n A random number.