| 1 |
/* rand.h: ISAAC interface prototypes and macros |
| 2 |
* |
| 3 |
* This package and its contents are released by the author into the |
| 4 |
* Public Domain, to the full extent permissible by law. For additional |
| 5 |
* information, please see the included `LICENSE' file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef RAND_H |
| 9 |
#define RAND_H 1 |
| 10 |
|
| 11 |
#include "standard.h" |
| 12 |
|
| 13 |
#define RANDSIZL (8) /* 8 for crypto, 4 for simulations */ |
| 14 |
#define RANDSIZ (1 << RANDSIZL) |
| 15 |
|
| 16 |
/* context of random number generator */ |
| 17 |
struct randctx { |
| 18 |
ub4 randcnt; |
| 19 |
ub4 randrsl[RANDSIZ]; |
| 20 |
ub4 randmem[RANDSIZ]; |
| 21 |
ub4 randa; |
| 22 |
ub4 randb; |
| 23 |
ub4 randc; |
| 24 |
}; |
| 25 |
typedef struct randctx randctx; |
| 26 |
|
| 27 |
/* Initialize using randrsl[0..RANDSIZ-1] as the seed */ |
| 28 |
void randinit(randctx *); |
| 29 |
static void isaac(randctx *); |
| 30 |
ub4 randInt(randctx *); |
| 31 |
|
| 32 |
/* Call rand(randctx *r) to get a single 32-bit random value |
| 33 |
* The code from this macro was moved to the ISAAC.xs file |
| 34 |
#define rand(r) \ |
| 35 |
(!(r)->randcnt-- ? \ |
| 36 |
(isaac(r), (r)->randcnt=RANDSIZ-1, (r)->randrsl[(r)->randcnt]) : \ |
| 37 |
(r)->randrsl[(r)->randcnt]) |
| 38 |
*/ |
| 39 |
|
| 40 |
#endif /* RAND_H */ |