Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>
long random(void);
The random() function uses a nonlinear additive feedback random-number generator employing a default state array size of 31 long integers to return successive pseudo-random numbers in the range from 0 to 231-1. The period of this random-number generator is approximately 16x(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 256 bytes of state information, the period of the random-number generator is greater than 269.
Like rand(), random() produces by default a sequence of numbers that can be duplicated by calling srandom() with 1 as the seed. The state information for the random functions is maintained on a per-thread basis. For example, calls to srandom() in one thread will have no effect on the numbers generated by calls to random() in another thread.
random() returns the generated pseudo-random number.