2 #define LFDS710_PRNG_MAX ( (lfds710_pal_uint_t) -1 )
4 /* TRD : the seed is from an on-line hardware RNG, using atmospheric noise
5 the URL below will generate another 16 random hex digits (e.g. a 64-bit number) and is
6 the RNG used to generate the number above (0x0a34655d34c092fe)
8 http://www.random.org/integers/?num=16&min=0&max=15&col=1&base=16&format=plain&rnd=new
10 the 32 bit seed is the upper half of the 64 bit seed
12 the "SplitMix" PRNG is from from Sebastiano vigna's site, CC0 license, http://xorshift.di.unimi.it/splitmix64.c
13 the 64-bit constants come directly from the source, the 32-bt constants are in fact the 32-bit murmurhash3 constants
16 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 4 )
17 #define LFDS710_PRNG_SEED 0x0a34655dUL
18 #define LFDS710_PRNG_SPLITMIX_MAGIC_RATIO 0x9E3779B9UL
19 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_ONE 16
20 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_TWO 13
21 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_THREE 16
22 #define LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_ONE 0x85ebca6bUL
23 #define LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_TWO 0xc2b2ae35UL
26 #if( LFDS710_PAL_ALIGN_SINGLE_POINTER == 8 )
27 #define LFDS710_PRNG_SEED 0x0a34655d34c092feULL
28 #define LFDS710_PRNG_SPLITMIX_MAGIC_RATIO 0x9E3779B97F4A7C15ULL
29 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_ONE 30
30 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_TWO 27
31 #define LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_THREE 31
32 #define LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_ONE 0xBF58476D1CE4E5B9ULL
33 #define LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_TWO 0x94D049BB133111EBULL
36 // TRD : struct lfds710_prng_state prng_state, lfds710_pal_uint_t random_value
37 #define LFDS710_PRNG_GENERATE( prng_state, random_value ) \
39 LFDS710_PAL_ATOMIC_ADD( &(prng_state).entropy, LFDS710_PRNG_SPLITMIX_MAGIC_RATIO, (random_value), lfds710_pal_uint_t ); \
40 LFDS710_PRNG_ST_MIXING_FUNCTION( random_value ); \
43 // TRD : struct lfds710_prng_state prng_st_state, lfds710_pal_uint_t random_value
44 #define LFDS710_PRNG_ST_GENERATE( prng_st_state, random_value ) \
46 (random_value) = ( (prng_st_state).entropy += LFDS710_PRNG_SPLITMIX_MAGIC_RATIO ); \
47 LFDS710_PRNG_ST_MIXING_FUNCTION( random_value ); \
50 // TRD : lfds710_pal_uint_t random_value
51 #define LFDS710_PRNG_ST_MIXING_FUNCTION( random_value ) \
53 (random_value) = ((random_value) ^ ((random_value) >> LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_ONE)) * LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_ONE; \
54 (random_value) = ((random_value) ^ ((random_value) >> LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_TWO)) * LFDS710_PRNG_SPLITMIX_MULTIPLY_CONSTANT_TWO; \
55 (random_value) = (random_value ^ (random_value >> LFDS710_PRNG_SPLITMIX_SHIFT_CONSTANT_THREE)); \
59 struct lfds710_prng_state
61 lfds710_pal_uint_t volatile LFDS710_PAL_ALIGN(LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES)
65 struct lfds710_prng_st_state
71 /***** public prototypes *****/
72 void lfds710_prng_init_valid_on_current_logical_core( struct lfds710_prng_state *ps, lfds710_pal_uint_t seed );
73 void lfds710_prng_st_init( struct lfds710_prng_st_state *psts, lfds710_pal_uint_t seed );