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
42 .Nd bad random number generator
48 .Fn srand "unsigned seed"
52 .Fn rand_r "unsigned *ctx"
55 The functions described in this manual page are not cryptographically
57 Applications which require unpredictable random numbers should use
64 function computes a sequence of pseudo-random integers in the range
71 function seeds the algorithm with the
74 Repeatable sequences of
76 output may be obtained by calling
81 is implicitly initialized as if
83 had been invoked explicitly.
88 is implemented using the same 128-byte state LFSR generator algorithm as
92 function is not (and can not be, because of its limited
96 implements the historical, poor-quality Park-Miller 32-bit LCG and should not
97 be used in new designs.
98 .Sh IMPLEMENTATION NOTES
102 is implemented with the same generator as
104 so the low-order bits should no longer be significantly worse than the
121 function is not part of
123 and is marked obsolescent in
125 It may be removed in a future revision of POSIX.
130 used the historical Park-Miller generator with 32 bits of state and produced
131 poor quality output, especially in the lower bits.
133 in earlier versions of
135 as well as other standards-conforming implementations, may continue to produce
138 .Em These functions should not be used in portable applications that want a
139 .Em high quality or high performance pseudorandom number generator .
140 One possible replacement,
142 is portable to Linux — but it is not especially fast, nor standardized.
144 If broader portability or better performance is desired, any of the widely
145 available and permissively licensed SFC64/32, JSF64/32, PCG64/32, or SplitMix64
146 algorithm implementations may be embedded in your application.
147 These algorithms have the benefit of requiring less space than
149 and being quite fast (in header inline implementations).