1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)rand.3 8.1 (Berkeley) 6/4/93
41 .Nd bad random number generator
47 .Fn srand "unsigned seed"
51 .Fn rand_r "unsigned *ctx"
54 The functions described in this manual page are not cryptographically
56 Applications which require unpredictable random numbers should use
63 function computes a sequence of pseudo-random integers in the range
70 function seeds the algorithm with the
73 Repeatable sequences of
75 output may be obtained by calling
80 is implicitly initialized as if
82 had been invoked explicitly.
87 is implemented using the same 128-byte state LFSR generator algorithm as
91 function is not (and can not be, because of its limited
95 implements the historical, poor-quality Park-Miller 32-bit LCG and should not
96 be used in new designs.
97 .Sh IMPLEMENTATION NOTES
101 is implemented with the same generator as
103 so the low-order bits should no longer be significantly worse than the
120 function is not part of
122 and is marked obsolescent in
124 It may be removed in a future revision of POSIX.
129 used the historical Park-Miller generator with 32 bits of state and produced
130 poor quality output, especially in the lower bits.
132 in earlier versions of
134 as well as other standards-conforming implementations, may continue to produce
137 .Em These functions should not be used in portable applications that want a
138 .Em high quality or high performance pseudorandom number generator .
139 One possible replacement,
141 is portable to Linux — but it is not especially fast, nor standardized.
143 If broader portability or better performance is desired, any of the widely
144 available and permissively licensed SFC64/32, JSF64/32, PCG64/32, or SplitMix64
145 algorithm implementations may be embedded in your application.
146 These algorithms have the benefit of requiring less space than
148 and being quite fast (in header inline implementations).