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
39 .Nd bad random number generator
45 .Fn srand "unsigned seed"
49 .Fn rand_r "unsigned *ctx"
52 The functions described in this manual page are not cryptographically
54 Applications which require unpredictable random numbers should use
61 function computes a sequence of pseudo-random integers in the range
68 function seeds the algorithm with the
71 Repeatable sequences of
73 output may be obtained by calling
78 is implicitly initialized as if
80 had been invoked explicitly.
85 is implemented using the same 128-byte state LFSR generator algorithm as
89 function is not (and can not be, because of its limited
93 implements the historical, poor-quality Park-Miller 32-bit LCG and should not
94 be used in new designs.
95 .Sh IMPLEMENTATION NOTES
99 is implemented with the same generator as
101 so the low-order bits should no longer be significantly worse than the
118 function is not part of
120 and is marked obsolescent in
122 It may be removed in a future revision of POSIX.
127 used the historical Park-Miller generator with 32 bits of state and produced
128 poor quality output, especially in the lower bits.
130 in earlier versions of
132 as well as other standards-conforming implementations, may continue to produce
135 .Em These functions should not be used in portable applications that want a
136 .Em high quality or high performance pseudorandom number generator .
137 One possible replacement,
139 is portable to Linux — but it is not especially fast, nor standardized.
141 If broader portability or better performance is desired, any of the widely
142 available and permissively licensed SFC64/32, JSF64/32, PCG64/32, or SplitMix64
143 algorithm implementations may be embedded in your application.
144 These algorithms have the benefit of requiring less space than
146 and being quite fast (in header inline implementations).