6f07671065b35b356db852294b7ed253e7fae5c4
7 * (c) 1999 Straylight/Edgeware
8 * (c) 2000 Mark Wooding
11 /*----- Licensing notice --------------------------------------------------*
13 * Copyright (c) 2000 Mark Wooding
14 * All rights reserved.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
23 * 2, Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
27 * 3. The name of the authors may not be used to endorse or promote
28 * products derived from this software without specific prior written
31 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
34 * NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
40 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
43 * Instead of accepting the above terms, you may redistribute and/or modify
44 * this software under the terms of either the GNU General Public License,
45 * or the GNU Library General Public License, published by the Free
46 * Software Foundation; either version 2 of the License, or (at your
47 * option) any later version.
50 /*----- Revision history --------------------------------------------------*
53 * Revision 1.2 2000/07/02 15:21:20 mdw
56 * Revision 1.1 2000/05/21 11:28:30 mdw
59 * --- Past lives (Catacomb) --- *
61 * Revision 1.1 1999/12/10 23:15:27 mdw
62 * Noncryptographic random number generator.
66 /*----- Notes on the Fibonacci generator ----------------------------------*
68 * The generator was originally suggested by G. J. Mitchell and D. P. Moore
69 * in 1957, and publicized by D. E. Knuth as Algorithm 3.2.2A in volume 2 of
70 * his work `The Art of Computer Programming'. The generator is simple: at
71 * each stage it emits %$x_n = (x_{n - 55} + x_{n - 24}) \bmod 2^{32}$%. The
72 * period is proven to be greater than %$2^{55}$%, and statistical properties
83 /*----- Header files ------------------------------------------------------*/
89 /*----- Magic constants ---------------------------------------------------*/
94 /*----- Data structures ---------------------------------------------------*/
96 typedef struct fibrand
{
101 /*----- Functions provided ------------------------------------------------*/
103 /* --- @fibrand_step@ --- *
105 * Arguments: @fibrand *f@ = pointer to Fibonacci generator context
107 * Returns: Next output from generator.
109 * Use: Steps the generator. Returns
110 * %$x_{i - 24} + x_{i - 55} \bmod 2^{32}$%.
113 extern uint32
fibrand_step(fibrand */
*f*/
);
115 /* --- @fibrand_lcseed@ --- *
117 * Arguments: @fibrand *f@ = pointer to Fibonacci generator context
118 * @uint32 seed@ = seed value
122 * Use: Initializes a Fibonacci generator using outputs from the
123 * @lcrand@ generator seeded from @seed@. This is faster than
124 * using a generic @lcrand@-based generator and @fibrand_rseed@
125 * because it uses raw outputs rather than uniformly distributed
129 extern void fibrand_lcseed(fibrand */
*f*/
, uint32
/*seed*/);
131 /* --- @fibrand_range@ --- *
133 * Arguments: @fibrand *f@ = pointer to Fibonacci generator context
136 * Returns: A uniformly distributed pseudorandom integer in the interval
140 extern uint32
fibrand_range(fibrand */
*f*/
, uint32
/*m*/);
142 /*----- That's all, folks -------------------------------------------------*/