Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r5d1ebb9 r2210cfc  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan 13 21:38:30 2022
    13 // Update Count     : 593
     12// Last Modified On : Mon Jan 10 17:07:21 2022
     13// Update Count     : 572
    1414//
    1515
    1616#include "stdlib.hfa"
    17 #include "bits/random.hfa"
     17//#include "concurrency/kernel/fwd.hfa"
    1818#include "concurrency/invoke.h"                                                 // random_state
    1919
     
    225225#define GENERATOR LCG
    226226
    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
     227inline uint32_t MarsagliaXor( uint32_t & state ) {
     228        state ^= state << 6;
     229        state ^= state >> 21;
     230        state ^= state << 7;
     231        return state;
     232} // MarsagliaXor
     233
     234inline uint32_t LCG( uint32_t & state ) {                               // linear congruential generator
     235        return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime!
     236} // LCG
     237
     238uint32_t __thread_seed = rdtscl();                                              // global thread seed
     239
     240void set_seed( uint32_t seed ) { __thread_seed = seed; }
     241uint32_t get_seed() { return  __thread_seed; }
    231242uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
    232243
    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]
     244uint32_t prng( void ) { return GENERATOR( __thread_seed ); } // [0,UINT_MAX]
    236245
    237246//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.