isaac64.h

Go to the documentation of this file.
00001 /*
00002 ------------------------------------------------------------------------------
00003 isaac64.h: Definitions for a fast cryptographic random number generator
00004 Bob Jenkins, 1996, Public Domain
00005 
00006 Modified for modularity by Tom Bartol and Rex Kerr
00007 
00008 Reference:
00009 http://burtleburtle.net/bob/rand/isaacafa.html
00010 Jenkins, R.J. (1996) ISAAC, in Fast Software Encryption, vol. 1039,
00011     ed. Gollmann, D.  Spinger-Verlag, Cambridge
00012 
00013 ------------------------------------------------------------------------------
00014 */
00015 #ifndef ISAAC64_H
00016 #define ISAAC64_H
00017 
00018 #define RANDSIZL   (4) /* I recommend 8 for crypto, 4 for simulations */
00019 #define RANDSIZ    (1<<RANDSIZL)
00020 #define RANDMAX    (2*RANDSIZ)
00021 
00022 typedef unsigned long long ub8;
00023 #if defined(u_int32_t)
00024 typedef u_int32_t       ub4;
00025 #else
00026 typedef unsigned int       ub4;
00027 #endif
00028 typedef unsigned short int ub2;
00029 typedef unsigned char      ub1;
00030 
00031 #define DBL32 (2.3283064365386962890625e-10)
00032 #define DBL53 (1.1102230246251565404236316680908203125e-16)
00033 #define DBL64 (5.42101086242752217003726400434970855712890625e-20)
00034 #define MSK53 0x001FFFFFFFFFFFFFLL
00035 
00036 struct isaac64_state
00037 {
00038   int randcnt;
00039   ub8 aa;
00040   ub8 bb;
00041   ub8 cc;
00042   ub8 randrsl[RANDSIZ];
00043   ub8 mm[RANDSIZ];
00044 };
00045 
00046 
00047 
00048 void isaac64_init(struct isaac64_state *rng, ub4 seed);
00049 
00050 void isaac64_generate(struct isaac64_state *rng);
00051 
00052 /*
00053 ------------------------------------------------------------------------------
00054 Macros to get individual random numbers
00055 ------------------------------------------------------------------------------
00056 */
00057 
00058 #define isaac64_uint32(rng) \
00059    (rng->randcnt>0 ? \
00060      ( *(((ub4 *)(rng->randrsl)) + (rng->randcnt-=1)) ) : \
00061      ( isaac64_generate(rng), \
00062        rng->randcnt=RANDMAX-1, \
00063        *(((ub4 *)(rng->randrsl)) + rng->randcnt) ))
00064 
00065 #define isaac64_uint64(rng) \
00066    (rng->randcnt>1 ? \
00067      ( *((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2))) ) : \
00068      ( isaac64_generate(rng), \
00069        rng->randcnt=RANDMAX-2, \
00070        *((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt)) ))
00071 
00072 #define isaac64_dbl32(rng) \
00073    (rng->randcnt>0 ? \
00074      ( DBL32 * (*(((ub4 *)(rng->randrsl)) + (rng->randcnt-=1)) ) ) : \
00075      ( isaac64_generate(rng), \
00076        rng->randcnt=RANDMAX-1, \
00077        DBL32 * (*(((ub4 *)(rng->randrsl)) + rng->randcnt)) ))
00078 
00079 #define isaac64_dbl53(rng) \
00080    (rng->randcnt>1 ? \
00081      ( DBL53 * ((*((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2))))>>11) ) : \
00082      ( isaac64_generate(rng), \
00083        rng->randcnt=RANDMAX-2, \
00084        DBL64 * ((*((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt)))>>11) ))
00085 
00086 #define isaac64_dbl64(rng) \
00087    (rng->randcnt>1 ? \
00088      ( DBL64 * (*((ub8 *)(((ub4 *)(rng->randrsl)) + (rng->randcnt-=2)))) ) : \
00089      ( isaac64_generate(rng), \
00090        rng->randcnt=RANDMAX-2, \
00091        DBL64 * (*((ub8 *)(((ub4 *)(rng->randrsl)) + rng->randcnt))) ))
00092 
00093 
00094 #endif  /* ISAAC64_H */
Generated on Mon Jun 13 08:10:27 2011 for NEURON by  doxygen 1.6.3