1 /* CC0 (Public domain) - see http://creativecommons.org/publicdomain/zero/1.0/ for details */
2 #if !defined(_isaac64_H)
3 # define _isaac64_H (1)
8 typedef struct isaac64_ctx isaac64_ctx;
12 #define ISAAC64_SZ_LOG (8)
13 #define ISAAC64_SZ (1<<ISAAC64_SZ_LOG)
14 #define ISAAC64_SEED_SZ_MAX (ISAAC64_SZ<<3)
18 /*ISAAC is the most advanced of a series of pseudo-random number generators
19 designed by Robert J. Jenkins Jr. in 1996.
20 http://www.burtleburtle.net/bob/rand/isaac.html
21 This is the 64-bit version.
23 ISAAC-64 generates a different sequence than ISAAC, but it uses the same
25 It uses 64-bit arithmetic.
26 It generates a 64-bit result every 19 instructions.
27 All cycles are at least 2**72 values, and the average cycle length is
31 uint64_t r[ISAAC64_SZ];
32 uint64_t m[ISAAC64_SZ];
40 * isaac64_init - Initialize an instance of the ISAAC64 random number generator.
41 * @_ctx: The ISAAC64 instance to initialize.
42 * @_seed: The specified seed bytes.
43 * This may be NULL if _nseed is less than or equal to zero.
44 * @_nseed: The number of bytes to use for the seed.
45 * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
48 void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
51 * isaac64_reseed - Mix a new batch of entropy into the current state.
52 * To reset ISAAC64 to a known state, call isaac64_init() again instead.
53 * @_ctx: The instance to reseed.
54 * @_seed: The specified seed bytes.
55 * This may be NULL if _nseed is zero.
56 * @_nseed: The number of bytes to use for the seed.
57 * If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
60 void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
62 * isaac64_next_uint64 - Return the next random 64-bit value.
63 * @_ctx: The ISAAC64 instance to generate the value with.
65 uint64_t isaac64_next_uint64(isaac64_ctx *_ctx);
67 * isaac64_next_uint - Uniform random integer less than the given value.
68 * @_ctx: The ISAAC64 instance to generate the value with.
69 * @_n: The upper bound on the range of numbers returned (not inclusive).
70 * This must be greater than zero and less than 2**64.
71 * To return integers in the full range 0...2**64-1, use
72 * isaac64_next_uint64() instead.
73 * Return: An integer uniformly distributed between 0 and _n-1 (inclusive).
75 uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n);
77 * isaac64_next_float - Uniform random float in the range [0,1).
78 * @_ctx: The ISAAC64 instance to generate the value with.
79 * Returns a high-quality float uniformly distributed between 0 (inclusive)
81 * All of the float's mantissa bits are random, e.g., the least significant bit
82 * may still be non-zero even if the value is less than 0.5, and any
83 * representable float in the range [0,1) has a chance to be returned, though
84 * values very close to zero become increasingly unlikely.
85 * To generate cheaper float values that do not have these properties, use
86 * ldexpf((float)isaac64_next_uint64(_ctx),-64);