NEURON
isaac64.h
Go to the documentation of this file.
1 /*
2 ------------------------------------------------------------------------------
3 isaac64.h: Definitions for a fast cryptographic random number generator
4 Bob Jenkins, 1996, Public Domain
5 
6 Modified for modularity by Tom Bartol and Rex Kerr
7 
8 Reference:
9 http://burtleburtle.net/bob/rand/isaacafa.html
10 Jenkins, R.J. (1996) ISAAC, in Fast Software Encryption, vol. 1039,
11  ed. Gollmann, D. Spinger-Verlag, Cambridge
12 
13 ------------------------------------------------------------------------------
14 */
15 #ifndef ISAAC64_H
16 #define ISAAC64_H
17 
18 #include <nrnconf.h>
19 #if defined(HAVE_STDINT_H)
20 #include <stdint.h>
21 #endif
22 
23 #define RANDSIZL (4) /* I recommend 8 for crypto, 4 for simulations */
24 #define RANDSIZ (1<<RANDSIZL)
25 #define RANDMAX (2*RANDSIZ)
26 
27 typedef unsigned long long ub8;
28 #if defined(uint32_t)
29 typedef uint32_t ub4;
30 #else
31 typedef unsigned int ub4;
32 #endif
33 typedef unsigned short int ub2;
34 typedef unsigned char ub1;
35 
36 #define DBL32 (2.3283064365386962890625e-10)
37 #define DBL53 (1.1102230246251565404236316680908203125e-16)
38 #define DBL64 (5.42101086242752217003726400434970855712890625e-20)
39 #define MSK53 0x001FFFFFFFFFFFFFLL
40 
42 {
43  int randcnt;
49 };
50 
51 
52 
53 void isaac64_init(struct isaac64_state *rng, ub4 seed);
54 
55 void isaac64_generate(struct isaac64_state *rng);
56 
57 /*
58 ------------------------------------------------------------------------------
59 Macros to get individual random numbers
60 ------------------------------------------------------------------------------
61 */
62 
63 #define isaac64_uint32(rng) \
64  (rng->randcnt>0 ? \
65  ( *(((ub4 *)(rng->randrsl)) + (rng->randcnt-=1)) ) : \
66  ( isaac64_generate(rng), \
67  rng->randcnt=RANDMAX-1, \
68  *(((ub4 *)(rng->randrsl)) + rng->randcnt) ))
69 
70 #define isaac64_uint64(rng) \
71  (rng->randcnt>1 ? \
72  ( *((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2))) ) : \
73  ( isaac64_generate(rng), \
74  rng->randcnt=RANDMAX-2, \
75  *((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt)) ))
76 
77 #define isaac64_dbl32(rng) \
78  (rng->randcnt>0 ? \
79  ( DBL32 * (*(((ub4 *)(rng->randrsl)) + (rng->randcnt-=1)) ) ) : \
80  ( isaac64_generate(rng), \
81  rng->randcnt=RANDMAX-1, \
82  DBL32 * (*(((ub4 *)(rng->randrsl)) + rng->randcnt)) ))
83 
84 #define isaac64_dbl53(rng) \
85  (rng->randcnt>1 ? \
86  ( DBL53 * ((*((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2))))>>11) ) : \
87  ( isaac64_generate(rng), \
88  rng->randcnt=RANDMAX-2, \
89  DBL64 * ((*((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt)))>>11) ))
90 
91 #define isaac64_dbl64(rng) \
92  (rng->randcnt>1 ? \
93  ( DBL64 * (*((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2)))) ) : \
94  ( isaac64_generate(rng), \
95  rng->randcnt=RANDMAX-2, \
96  DBL64 * (*((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt))) ))
97 
98 
99 #endif /* ISAAC64_H */
void isaac64_generate(struct isaac64_state *rng)
Definition: isaac64.cpp:42
ub8 mm[RANDSIZ]
Definition: isaac64.h:48
unsigned short int ub2
Definition: isaac64.h:33
unsigned char ub1
Definition: isaac64.h:34
unsigned int ub4
Definition: isaac64.h:31
void isaac64_init(struct isaac64_state *rng, ub4 seed)
Definition: isaac64.cpp:67
unsigned long long ub8
Definition: isaac64.h:27
ub8 randrsl[RANDSIZ]
Definition: isaac64.h:47
int randcnt
Definition: isaac64.h:43
uint uint32_t
#define RANDSIZ
Definition: isaac64.h:24