Ignore:
Timestamp:
Dec 29, 2021, 5:06:07 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
aa0a1ad, db1ebed
Parents:
7a6ae53
git-author:
Peter A. Buhr <pabuhr@…> (12/29/21 17:00:15)
git-committer:
Peter A. Buhr <pabuhr@…> (12/29/21 17:06:07)
Message:

change range of integral random( u, l ) to [l,u], first attempt at specialized PRNG

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r7a6ae53 raa8e24c3  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 12 07:46:09 2020
    13 // Update Count     : 503
     12// Last Modified On : Wed Dec 29 15:32:44 2021
     13// Update Count     : 512
    1414//
    1515
     
    221221//---------------------------------------
    222222
    223 bool threading_enabled(void) __attribute__((weak)) {
    224         return false;
    225 }
     223static uint32_t seed = 0;                                                               // current seed
     224static thread_local uint32_t state;                                             // random state
     225
     226void set_seed( uint32_t seed_ ) { state = seed = seed_; }
     227uint32_t get_seed() { return seed; }
     228
     229#define GENERATOR LCG
     230
     231inline 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
     240inline 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
     246uint32_t prng( PRNG & prng ) with( prng ) { callcnt += 1; return GENERATOR( state ); }
     247
     248uint32_t prng( void ) { return GENERATOR( state ); }
     249
     250//---------------------------------------
     251
     252bool threading_enabled( void ) __attribute__(( weak )) { return false; }
    226253
    227254// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.