well512.cc (1308B)
1 /* 2 * WELL512 PRNG written by Chris Lomont 3 * www.lomont.org/Math/Papers/2008/Lomont_PRNG_2008.pdf 4 */ 5 6 #include "../intrinsics.h" 7 #include "well512.h" 8 9 void rng_well512_init( RNGWell512 * rng ) { 10 // generated with 11 // for i in (seq 1 16); od -A n -t u -N 4 /dev/urandom; end 12 rng->state[ 0 ] = 3485465937; 13 rng->state[ 1 ] = 619988921; 14 rng->state[ 2 ] = 1151619954; 15 rng->state[ 3 ] = 1259802506; 16 rng->state[ 4 ] = 2391016736; 17 rng->state[ 5 ] = 1833603341; 18 rng->state[ 6 ] = 3529478173; 19 rng->state[ 7 ] = 2843655677; 20 rng->state[ 8 ] = 1227810011; 21 rng->state[ 9 ] = 3849695542; 22 rng->state[ 10 ] = 3734095823; 23 rng->state[ 11 ] = 582871035; 24 rng->state[ 12 ] = 3217102166; 25 rng->state[ 13 ] = 1925191046; 26 rng->state[ 14 ] = 1602871528; 27 rng->state[ 15 ] = 1661469209; 28 rng->index = 0; 29 } 30 31 u32 rng_well512_next( RNGWell512 * rng ) { 32 u32 a, b, c, d; 33 a = rng->state[rng->index]; 34 c = rng->state[(rng->index+13)&15]; 35 b = a^c^(a<<16)^(c<<15); 36 c = rng->state[(rng->index+9)&15]; 37 c ^= (c>>11); 38 a = rng->state[rng->index] = b^c; 39 d = a^((a<<5)&0xDA442D24UL); 40 rng->index = (rng->index + 15)&15; 41 a = rng->state[rng->index]; 42 rng->state[rng->index] = a^b^d^(a<<2)^(b<<18)^(c<<28); 43 return rng->state[rng->index]; 44 } 45 46 u32 rng_next( RNGWell512 * rng ) { 47 return rng_well512_next( rng ); 48 }