| Main index | Section 3 | 日本語 | Deutsch | Options |
#include <stdlib.h>
The rand() function computes a sequence of pseudo-random integers in the range of 0 to RAND_MAX, inclusive.
The srand() function seeds the algorithm with the seed parameter. Repeatable sequences of rand() output may be obtained by calling srand() with the same seed. rand() is implicitly initialized as if srand(1) had been invoked explicitly.
In FreeBSD 13, rand() is implemented using the same 128-byte state LFSR generator algorithm as random(3). However, the legacy rand_r() function is not (and can not be, because of its limited *ctx size). rand_r() implements the historical, poor-quality Park-Miller 32-bit LCG and should not be used in new designs.
The rand_r() function is not part of ISO/IEC 9899:1990 ("ISO C90") and is marked obsolescent in IEEE Std 1003.1-2008 ("POSIX.1"). It may be removed in a future revision of POSIX.
These functions should not be used in portable applications that want a high quality or high performance pseudorandom number generator. One possible replacement, random(3), is portable to Linux â but it is not especially fast, nor standardized.
If broader portability or better performance is desired, any of the widely available and permissively licensed SFC64/32, JSF64/32, PCG64/32, or SplitMix64 algorithm implementations may be embedded in your application. These algorithms have the benefit of requiring less space than random(3) and being quite fast (in header inline implementations).
| RAND (3) | February 1, 2020 |
| Main index | Section 3 | 日本語 | Deutsch | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
