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
31 * For each of the currently supported random number generators, we have a
32 * break value on the amount of state information (you need at least this
33 * many bytes of state info to support this random number generator), a degree
34 * for the polynomial (actually a trinomial) that the R.N.G. is based on, and
35 * the separation between the two lower order coefficients of the trinomial.
37 #define TYPE_0 0 /* linear congruential */
42 #define TYPE_1 1 /* x**7 + x**3 + 1 */
47 #define TYPE_2 2 /* x**15 + x + 1 */
52 #define TYPE_3 3 /* x**31 + x**3 + 1 */
57 #define TYPE_4 4 /* x**63 + x + 1 */
63 * Array versions of the above information to make code run faster --
64 * relies on fact that TYPE_i == i.
66 #define MAX_TYPES 5 /* max number of types above */
68 /* A full instance of the random(3) generator. */
69 struct __random_state {
76 uint32_t *rst_end_ptr;
77 /* Flexible array member must be last. */
78 uint32_t rst_randtbl[];
81 struct __random_state *allocatestate(unsigned type);
82 int initstate_r(struct __random_state *, unsigned, uint32_t *, size_t);
83 long random_r(struct __random_state *);
84 void srandom_r(struct __random_state *, unsigned);
85 void srandomdev_r(struct __random_state *);