1 /* 2 ------------------------------------------------------------------------------ 3 isaac.h: definitions for a random number generator 4 MODIFIED: 5 960327: Creation (addition of randinit, really) 6 970719: use context, not global variables, for internal state 7 980324: renamed seed to flag 8 980605: recommend RANDSIZL=4 for noncryptography. 9 991209: modified for inclusion with GNU Backgammon by Gary Wong 10 070121: modified for inclusion with flam3 by Erik Reckase 11 ------------------------------------------------------------------------------ 12 */ 13 14 #include "isaacs.h" 15 16 #ifndef _ISAAC_H_ 17 #define _ISAAC_H_ 18 19 #define RANDSIZL (4) /* I recommend 8 for crypto, 4 for simulations */ 20 #define RANDSIZ (1<<RANDSIZL) 21 22 /* context of random number generator */ 23 struct randctx 24 { 25 ub4 randcnt; 26 ub4 randrsl[RANDSIZ]; 27 ub4 randmem[RANDSIZ]; 28 ub4 randa; 29 ub4 randb; 30 ub4 randc; 31 }; 32 typedef struct randctx randctx; 33 34 /* 35 ------------------------------------------------------------------------------ 36 If (flag==TRUE), then use the contents of randrsl[0..RANDSIZ-1] as the seed. 37 ------------------------------------------------------------------------------ 38 */ 39 void irandinit( randctx *r, word flag ); 40 41 void isaac( randctx *r ); 42 43 44 /* 45 ------------------------------------------------------------------------------ 46 Call irand(/o_ randctx *r _o/) to retrieve a single 32-bit random value 47 ------------------------------------------------------------------------------ 48 */ 49 #define irand(r) \ 50 (!(r)->randcnt-- ? \ 51 (isaac(r), (r)->randcnt=RANDSIZ-1, (r)->randrsl[(r)->randcnt]) : \ 52 (r)->randrsl[(r)->randcnt]) 53 54 #endif 55 56 57