1 #if !defined(_isaac64_H)
2 # define _isaac64_H (1)
7 typedef struct isaac64_ctx isaac64_ctx;
11 #define ISAAC64_SZ_LOG (8)
12 #define ISAAC64_SZ (1<<ISAAC64_SZ_LOG)
13 #define ISAAC64_SEED_SZ_MAX (ISAAC64_SZ<<3)
17 /*ISAAC is the most advanced of a series of pseudo-random number generators
18 designed by Robert J. Jenkins Jr. in 1996.
19 http://www.burtleburtle.net/bob/rand/isaac.html
20 This is the 64-bit version.
22 ISAAC-64 generates a different sequence than ISAAC, but it uses the same
24 It uses 64-bit arithmetic.
25 It generates a 64-bit result every 19 instructions.
26 All cycles are at least 2**72 values, and the average cycle length is
30 uint64_t r[ISAAC64_SZ];
31 uint64_t m[ISAAC64_SZ];
39 * isaac64_init - Initialize an instance of the ISAAC64 random number generator.
40 * @_ctx: The ISAAC64 instance to initialize.
41 * @_seed: The specified seed bytes.
42 * This may be NULL if _nseed is less than or equal to zero.
43 * @_nseed: The number of bytes to use for the seed.
44 * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
47 void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
50 * isaac64_reseed - Mix a new batch of entropy into the current state.
51 * To reset ISAAC64 to a known state, call isaac64_init() again instead.
52 * @_ctx: The instance to reseed.
53 * @_seed: The specified seed bytes.
54 * This may be NULL if _nseed is zero.
55 * @_nseed: The number of bytes to use for the seed.
56 * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
59 void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
61 * isaac64_next_uint64 - Return the next random 64-bit value.
62 * @_ctx: The ISAAC64 instance to generate the value with.
64 uint64_t isaac64_next_uint64(isaac64_ctx *_ctx);
66 * isaac64_next_uint - Uniform random integer less than the given value.
67 * @_ctx: The ISAAC64 instance to generate the value with.
68 * @_n: The upper bound on the range of numbers returned (not inclusive).
69 * This must be greater than zero and less than 2**64.
70 * To return integers in the full range 0...2**64-1, use
71 * isaac64_next_uint64() instead.
72 * Return: An integer uniformly distributed between 0 and _n-1 (inclusive).
74 uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n);
76 * isaac64_next_float - Uniform random float in the range [0,1).
77 * @_ctx: The ISAAC64 instance to generate the value with.
78 * Returns a high-quality float uniformly distributed between 0 (inclusive)
80 * All of the float's mantissa bits are random, e.g., the least significant bit
81 * may still be non-zero even if the value is less than 0.5, and any
82 * representable float in the range [0,1) has a chance to be returned, though
83 * values very close to zero become increasingly unlikely.
84 * To generate cheaper float values that do not have these properties, use
85 * ldexpf((float)isaac64_next_uint64(_ctx),-64);
87 float isaac64_next_float(isaac64_ctx *_ctx);
89 * isaac64_next_signed_float - Uniform random float in the range (-1,1).
90 * @_ctx: The ISAAC64 instance to generate the value with.
91 * Returns a high-quality float uniformly distributed between -1 and 1
93 * All of the float's mantissa bits are random, e.g., the least significant bit
94 * may still be non-zero even if the magnitude is less than 0.5, and any
95 * representable float in the range (-1,1) has a chance to be returned, though
96 * values very close to zero become increasingly unlikely.
97 * To generate cheaper float values that do not have these properties, use
98 * ldexpf((float)isaac64_next_uint64(_ctx),-63)-1;
99 * though this returns values in the range [-1,1).
101 float isaac64_next_signed_float(isaac64_ctx *_ctx);
103 * isaac64_next_double - Uniform random double in the range [0,1).
104 * @_ctx: The ISAAC64 instance to generate the value with.
105 * Returns a high-quality double uniformly distributed between 0 (inclusive)
107 * All of the double's mantissa bits are random, e.g., the least significant
108 * bit may still be non-zero even if the value is less than 0.5, and any
109 * representable double in the range [0,1) has a chance to be returned, though
110 * values very close to zero become increasingly unlikely.
111 * To generate cheaper double values that do not have these properties, use
112 * ldexp((double)isaac64_next_uint64(_ctx),-64);
114 double isaac64_next_double(isaac64_ctx *_ctx);
116 * isaac64_next_signed_double - Uniform random double in the range (-1,1).
117 * @_ctx: The ISAAC64 instance to generate the value with.
118 * Returns a high-quality double uniformly distributed between -1 and 1
120 * All of the double's mantissa bits are random, e.g., the least significant
121 * bit may still be non-zero even if the value is less than 0.5, and any
122 * representable double in the range (-1,1) has a chance to be returned,
123 * though values very close to zero become increasingly unlikely.
124 * To generate cheaper double values that do not have these properties, use
125 * ldexp((double)isaac64_next_uint64(_ctx),-63)-1;
126 * though this returns values in the range [-1,1).
128 double isaac64_next_signed_double(isaac64_ctx *_ctx);