Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r1959528 r5d1ebb9  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 12 16:25:36 2022
    13 // Update Count     : 578
     12// Last Modified On : Thu Jan 13 21:38:30 2022
     13// Update Count     : 593
    1414//
    1515
    1616#include "stdlib.hfa"
    17 //#include "concurrency/kernel/fwd.hfa"
     17#include "bits/random.hfa"
    1818#include "concurrency/invoke.h"                                                 // random_state
    1919
     
    223223//---------------------------------------
    224224
    225 // Pipelined to allow OoO overlap with reduced dependencies. Critically, return the current value, and compute and store
    226 // the next value.
    227 
    228225#define GENERATOR LCG
    229226
    230 static inline uint32_t MarsagliaXor( uint32_t & state ) {
    231         uint32_t ret = state;
    232         state ^= state << 6;
    233         state ^= state >> 21;
    234         state ^= state << 7;
    235         return ret;
    236 } // MarsagliaXor
    237 
    238 static inline uint32_t LCG( uint32_t & state ) {                // linear congruential generator
    239         uint32_t ret = state;
    240         state = 36969 * (state & 65535) + (state >> 16);        // 36969 is NOT prime! No not change it!
    241         return ret;
    242 } // LCG
    243 
    244 uint32_t __global_random_seed;
     227uint32_t __global_random_seed;                                                  // sequential/concurrent
     228uint32_t __global_random_state;                                         // sequential only
    245229
    246230void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; GENERATOR( state ); } // set seed
    247231uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
    248232
    249 void set_seed( uint32_t seed ) {
    250         active_thread()->random_state = __global_random_seed = seed;
    251         GENERATOR( active_thread()->random_state );
    252 } // set_seed
     233void set_seed( uint32_t seed ) { __global_random_seed = seed; GENERATOR( __global_random_state ); }
    253234uint32_t get_seed() { return __global_random_seed; }
    254 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]
     235uint32_t prng( void ) { return GENERATOR( __global_random_state ); } // [0,UINT_MAX]
    255236
    256237//---------------------------------------
Note: See TracChangeset for help on using the changeset viewer.