Changes in libcfa/src/stdlib.cfa [2210cfc:15b05c8]
- File:
-
- 1 edited
-
libcfa/src/stdlib.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.cfa
r2210cfc r15b05c8 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 17:07:21202213 // Update Count : 5 7212 // Last Modified On : Mon Jan 3 09:36:27 2022 13 // Update Count : 519 14 14 // 15 15 16 16 #include "stdlib.hfa" 17 //#include "concurrency/kernel/fwd.hfa"18 #include "concurrency/invoke.h" // random_state19 17 20 18 //--------------------------------------- … … 223 221 //--------------------------------------- 224 222 223 static uint32_t seed = 0; // current seed 224 static thread_local uint32_t state; // random state 225 226 void set_seed( uint32_t seed_ ) { state = seed = seed_; } 227 uint32_t get_seed() { return seed; } 228 225 229 #define GENERATOR LCG 226 230 227 231 inline uint32_t MarsagliaXor( uint32_t & state ) { 232 if ( unlikely( seed == 0 ) ) set_seed( rdtscl() ); 233 else if ( unlikely( state == 0 ) ) state = seed; 228 234 state ^= state << 6; 229 235 state ^= state >> 21; … … 233 239 234 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; 235 243 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 236 244 } // LCG 237 245 238 uint32_t __thread_seed = rdtscl(); // global thread seed239 240 void set_seed( uint32_t seed ) { __thread_seed = seed; }241 uint32_t get_seed() { return __thread_seed; }242 246 uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); } 243 247 244 uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX]248 uint32_t prng( void ) { return GENERATOR( state ); } 245 249 246 250 //---------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.