1 .\" Copyright (c) 1983, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .Nd non-cryptographic pseudorandom number generator; routines for changing generators
45 .Fn srandom "unsigned int seed"
49 .Fn initstate "unsigned int seed" "char *state" "size_t n"
51 .Fn setstate "char *state"
54 The functions described in this manual page are not secure.
55 Applications which require unpredictable random numbers should use
60 Unless initialized with less than 32 bytes of state, the
63 uses a non-linear additive feedback random number generator employing a
64 default table of size 31 long integers to return successive pseudo-random
65 numbers in the range from 0 to
66 .if t 2\u\s731\s10\d\(mi1.
68 The period of this random number generator is very large, approximately
69 .if t 16\(mu(2\u\s731\s10\d\(mi1).
70 .if n 16*((2**31)\(mi1).
72 If initialized with less than 32 bytes of state,
74 uses the poor-quality 32-bit Park-Miller LCG.
80 functions are analagous to
88 is implicitly initialized as if
90 had been invoked explicitly.
94 routine initializes the state array using random numbers obtained from the
96 This can generate states which are impossible to reproduce by calling
98 because the succeeding terms in the state buffer are no longer derived from the
99 Park-Miller LCG algorithm applied to a fixed seed.
103 routine initializes the provided state array of
105 values and uses it in future
112 the underlying object must be a naturally aligned array of 32-bit values.)
113 The size of the state array (in bytes) is used by
115 to decide how sophisticated a random number generator it should use \(em the
116 more state, the better the random numbers will be.
117 (Current "optimal" values for the amount of state information are
118 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
119 the nearest known amount.
120 Using less than 8 bytes will cause an error.)
128 returns a pointer to the previous state information array.
134 to using the provided state.
135 It returns a pointer to the previous state.
137 Once a state array has been initialized, it may be restarted at a
138 different point either by calling
140 (with the desired seed, the state array, and its size) or by calling
143 (with the state array) and
145 (with the desired seed).
146 The advantage of calling both
150 is that the size of the state array does not have to be remembered after
153 With 256 bytes of state information, the period of the random number
154 generator is greater than
155 .if t 2\u\s769\s10\d,
157 which should be sufficient for most purposes.
161 is called with less than 8 bytes of state information, or if
163 detects that the state information has been garbled,
172 functions appeared in