2 * Copyright 2020 Conrad Meyer <cem@FreeBSD.org>. 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.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * For each of the currently supported random number generators, we have a
30 * break value on the amount of state information (you need at least this
31 * many bytes of state info to support this random number generator), a degree
32 * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
33 * the separation between the two lower order coefficients of the trinomial.
35 #define TYPE_0 0 /* linear congruential */
40 #define TYPE_1 1 /* x**7 + x**3 + 1 */
45 #define TYPE_2 2 /* x**15 + x + 1 */
50 #define TYPE_3 3 /* x**31 + x**3 + 1 */
55 #define TYPE_4 4 /* x**63 + x + 1 */
61 * Array versions of the above information to make code run faster --
62 * relies on fact that TYPE_i == i.
64 #define MAX_TYPES 5 /* max number of types above */
66 /* A full instance of the random(3) generator. */
67 struct __random_state {
74 uint32_t *rst_end_ptr;
75 /* Flexible array member must be last. */
76 uint32_t rst_randtbl[];
79 struct __random_state *allocatestate(unsigned type);
80 int initstate_r(struct __random_state *, unsigned, uint32_t *, size_t);
81 long random_r(struct __random_state *);
82 void srandom_r(struct __random_state *, unsigned);
83 void srandomdev_r(struct __random_state *);