Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/thread.cfa

    r1959528 r5d1ebb9  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan 12 18:28:18 2022
    13 // Update Count     : 35
     12// Last Modified On : Thu Jan 13 20:11:55 2022
     13// Update Count     : 42
    1414//
    1515
     
    2424#define __CFA_INVOKE_PRIVATE__
    2525#include "invoke.h"
    26 
    27 uint64_t thread_rand();
    2826
    2927extern uint32_t __global_random_seed;
     
    174172}
    175173
    176 uint64_t thread_rand() {
    177         disable_interrupts();
    178         uint64_t ret = __tls_rand();
    179         enable_interrupts();
    180         return ret;
    181 }
    182  
     174//-----------------------------------------------------------------------------
    183175#define GENERATOR LCG
    184176
    185 static inline uint32_t MarsagliaXor( uint32_t & state ) {
    186         uint32_t ret = state;
    187         state ^= state << 6;
    188         state ^= state >> 21;
    189         state ^= state << 7;
    190         return ret;
    191 } // MarsagliaXor
    192 
    193 static inline uint32_t LCG( uint32_t & state ) {                // linear congruential generator
    194         uint32_t ret = state;
    195         state = 36969 * (state & 65535) + (state >> 16);        // 36969 is NOT prime! No not change it!
    196         return ret;
    197 } // LCG
    198 
    199 void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __global_random_seed = seed; }
     177void set_seed( uint32_t seed ) {
     178        active_thread()->random_state = __global_random_seed = seed;
     179        GENERATOR( active_thread()->random_state );
     180} // set_seed
    200181uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX]
    201182
Note: See TracChangeset for help on using the changeset viewer.