prand.h
Go to the documentation of this file.
1 #pragma once
2 
94 
95 #include <inttypes.h>
96 #include <stdbool.h>
97 
105 typedef struct{
107  uint64_t state_size;
109  uint32_t (*get_u32)(void*);
113  bool (*fixup_state)(void*);
115  char state[];
116 } cr8r_prng;
117 
125 bool cr8r_prng_seed(cr8r_prng*, uint64_t);
126 
134 
139 
143 void cr8r_prng_get_bytes(cr8r_prng*, uint64_t size, void *buf);
144 
153 uint64_t cr8r_prng_uniform_u64(cr8r_prng*, uint64_t a, uint64_t b);
154 
160 
192 uint64_t cr8r_prng_log_mod_t64(uint64_t h);
193 
198 extern const uint64_t cr8r_prng_2tg_t64[4];
199 
200 // these constants are taken from the standard MT19937-64 generator configuration
201 #define CR8R_PRNG_MT_N 312
202 #define CR8R_PRNG_MT_M 156
203 #define CR8R_PRNG_MT_R 31
204 #define CR8R_PRNG_MT_A 0xB5026F5AA96619E9
205 #define CR8R_PRNG_MT_U 29
206 #define CR8R_PRNG_MT_D 0x5555555555555555
207 #define CR8R_PRNG_MT_S 17
208 #define CR8R_PRNG_MT_B 0x71D67FFFEDA60000
209 #define CR8R_PRNG_MT_T 37
210 #define CR8R_PRNG_MT_C 0xFFF7EEE000000000
211 #define CR8R_PRNG_MT_L 43
212 #define CR8R_PRNG_MT_F 6364136223846793005
213 
214 #define CR8R_PRNG_LFM_R 127
215 #define CR8R_PRNG_LFM_S 97
216 
217 #define CR8R_DEFAULT_PRNG_SM_SEED 0xd20499955ff0e57c
218 
219 #define CR8R_DEFAULT_PRNG_LCG_SEED 0xe9352d1427990d8e
220 
228 
245 
262 
277 
287 cr8r_prng *cr8r_prng_init_mt(uint64_t seed);
288 
301 
310 
313 
319 
325 
cr8r_prng * cr8r_default_prng_splitmix
Default SplitMix prng, automatically used to extend seed values to state values if needed.
const uint64_t cr8r_prng_2tg_t64[4]
The multipliers for 3**x in the result of cr8r_prng_log_mod_t64 This is the Klein 4 group embedded in...
void cr8r_prng_xoro_jump_t192(cr8r_prng *)
Jump a xoro based prng forwards by 2**192 steps quickly.
uint64_t cr8r_prng_get_u64(cr8r_prng *)
Get a single uint64_t from a prng.
cr8r_prng * cr8r_prng_init_splitmix(uint64_t seed)
Create a PRNG based on Vigna's version of SplitMix.
cr8r_prng * cr8r_prng_init_lfg_m(uint64_t seed)
Create a PRNG based on a Multiplication Lagged Fibonnacci Generator.
uint32_t cr8r_prng_get_u32(cr8r_prng *)
Get a single uint32_t from a prng.
uint64_t cr8r_prng_log_mod_t64(uint64_t h)
Find x (the discrete logarithm) so that h = g**x mod 2**64.
void cr8r_prng_xoro_jump_t128(cr8r_prng *)
Jump a xoro based prng forwards by 2**128 steps quickly.
uint64_t cr8r_prng_uniform_u64(cr8r_prng *, uint64_t a, uint64_t b)
Get a uint64_t which is uniformly distributed on [a, b).
cr8r_prng * cr8r_prng_init_lfg_sc(uint64_t seed)
Create a PRNG based on a Subtract with Carry Lagged Fibonacci Generator.
cr8r_prng * cr8r_prng_init_system()
Create a PRNG based on the system's prng device.
cr8r_prng * cr8r_prng_init_mt(uint64_t seed)
Create a PRNG based on a Mersenne Twister Generator.
bool cr8r_prng_seed(cr8r_prng *, uint64_t)
Set the state of a prng.
cr8r_prng * cr8r_prng_init_lcg(uint64_t seed)
Create a PRNG based on a Linear Congruential Generator.
double cr8r_prng_uniform01_double(cr8r_prng *)
Get a double which is uniformly distributed on [0, 1)
cr8r_prng * cr8r_prng_init_xoro(uint64_t seed)
Create a PRNG based on Vigna and Blackman's Xoroshiro256** algorithm.
void cr8r_prng_get_bytes(cr8r_prng *, uint64_t size, void *buf)
Fill a buffer with random bytes from a prng.
A PseudoRandom Number Generator.
Definition: prand.h:105
uint64_t state_size
Size of the state information for the implementation, in bytes.
Definition: prand.h:107