Changeset 12c1eef for libcfa/src/stdlib.cfa
- Timestamp:
- Jan 19, 2022, 2:36:56 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 97c215f
- Parents:
- 5235d49 (diff), 6a33e40 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r5235d49 r12c1eef 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 29 15:32:44 202113 // Update Count : 5 1212 // Last Modified On : Thu Jan 13 21:38:30 2022 13 // Update Count : 593 14 14 // 15 15 16 16 #include "stdlib.hfa" 17 #include "bits/random.hfa" 18 #include "concurrency/invoke.h" // random_state 17 19 18 20 //--------------------------------------- … … 221 223 //--------------------------------------- 222 224 223 static uint32_t seed = 0; // current seed224 static thread_local uint32_t state; // random state225 226 void set_seed( uint32_t seed_ ) { state = seed = seed_; }227 uint32_t get_seed() { return seed; }228 229 225 #define GENERATOR LCG 230 226 231 inline uint32_t MarsagliaXor( uint32_t & state ) { 232 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() ); 233 else if ( unlikely( state == 0 ) ) state = seed; 234 state ^= state << 6; 235 state ^= state >> 21; 236 state ^= state << 7; 237 return state; 238 } // MarsagliaXor 239 240 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 241 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() ); 242 else if ( unlikely( state == 0 ) ) state = seed; 243 return state = 36973 * (state & 65535) + (state >> 16); 244 } // LCG 245 227 uint32_t __global_random_seed; // sequential/concurrent 228 uint32_t __global_random_state; // sequential only 229 230 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed 246 231 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 247 232 248 uint32_t prng( void ) { return GENERATOR( state ); } 233 void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); } 234 uint32_t get_seed() { return __global_random_seed; } 235 uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX] 249 236 250 237 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.