Changeset 12b006c for libcfa/src
- Timestamp:
- Mar 20, 2023, 5:06:26 PM (21 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 0e16a2d, 90fb672
- Parents:
- 09965e5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/random.hfa
r09965e5 r12b006c 137 137 // pseudo-random number generators. 138 138 static inline uint64_t splitmix64( uint64_t & state ) { 139 state += 0x9e3779b97f4a7c15; /* increment the state variable */140 uint64_t z = state; /* copy the state to a working variable */141 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; /* xor the variable with the variable right bit shifted 30 then multiply by a constant */142 z = (z ^ (z >> 27)) * 0x94d049bb133111eb; /* xor the variable with the variable right bit shifted 27 then multiply by a constant */143 return z ^ (z >> 31); /* return the variable xored with itself right bit shifted 31 */144 } 139 state += 0x9e3779b97f4a7c15; 140 uint64_t z = state; 141 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; 142 z = (z ^ (z >> 27)) * 0x94d049bb133111eb; 143 return z ^ (z >> 31); 144 } // splitmix64 145 145 146 146 static inline void splitmix64_set_seed( uint64_t & state , uint64_t seed ) { 147 147 state = seed; 148 148 splitmix64( state ); // prime 149 } // splitmix32_set_seed 150 149 } // splitmix64_set_seed 151 150 152 151 // Splitmix32 … … 162 161 z = (z ^ (z >> 13)) * 0xc2b2ae35; 163 162 return z ^ (z >> 16); 164 } 165 166 static inline void splitmix32_set_seed( uint32_t & state 163 } // splitmix32 164 165 static inline void splitmix32_set_seed( uint32_t & state, uint64_t seed ) { 167 166 state = seed; 168 167 splitmix32( state ); // prime … … 229 228 static inline void xoshiro256pp_set_seed( xoshiro256pp_t & state, uint64_t seed ) { 230 229 // these are done explicitly in this order to attain repeatable seeding. 231 // do not call splitmix 32directly in the state init since order of argument evaluation230 // do not call splitmix64 directly in the state init since order of argument evaluation 232 231 // may not be consistent leading to irreproducible seeding 233 232 uint64_t seed1 = splitmix64( seed );
Note: See TracChangeset
for help on using the changeset viewer.