Changeset 1959528 for libcfa/src/stdlib.hfa
- Timestamp:
- Jan 12, 2022, 6:34:58 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 00f5fde
- Parents:
- a10f6b4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
ra10f6b4 r1959528 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 17:03:18 202213 // Update Count : 6 1912 // Last Modified On : Wed Jan 12 09:09:48 2022 13 // Update Count : 620 14 14 // 15 15 … … 386 386 //--------------------------------------- 387 387 388 // Sequential Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 389 // 390 // Declaration : 391 // PRNG sprng = { 1009 } - set starting seed versus random seed 392 // 393 // Interface : 394 // set_seed( sprng, 1009 ) - set starting seed for ALL kernel threads versus random seed 395 // get_seed( sprng ) - read seed 396 // prng( sprng ) - generate random value in range [0,UINT_MAX] 397 // prng( sprng, u ) - generate random value in range [0,u) 398 // prng( sprng, l, u ) - generate random value in range [l,u] 399 // calls( sprng ) - number of generated random value so far 400 // 401 // Examples : generate random number between 5-21 402 // prng( sprng ) % 17 + 5; values 0-16 + 5 = 5-21 403 // prng( sprng, 16 + 1 ) + 5; 404 // prng( sprng, 5, 21 ); 405 // calls( sprng ); 406 388 407 struct PRNG { 389 408 uint32_t callcnt; // call count … … 392 411 }; // PRNG 393 412 413 void set_seed( PRNG & prng, uint32_t seed_ ); 394 414 uint32_t prng( PRNG & prng ) __attribute__(( warn_unused_result )); // [0,UINT_MAX] 395 415 static inline { 396 void set_seed( PRNG & prng, uint32_t seed_ ) with( prng ) { state = seed = seed_; } // set seed397 416 void ?{}( PRNG & prng ) { set_seed( prng, rdtscl() ); } // random seed 398 417 void ?{}( PRNG & prng, uint32_t seed ) { set_seed( prng, seed ); } // fixed seed … … 403 422 } // distribution 404 423 424 // Concurrent Pseudo Random-Number Generator : generate repeatable sequence of values that appear random. 425 // 426 // Interface : 427 // set_seed( 1009 ) - fixed seed for all kernel threads versus random seed 428 // get_seed() - read seed 429 // prng() - generate random value in range [0,UINT_MAX] 430 // prng( u ) - generate random value in range [0,u) 431 // prng( l, u ) - generate random value in range [l,u] 432 // 433 // Examples : generate random number between 5-21 434 // prng() % 17 + 5; values 0-16 + 5 = 5-21 435 // prng( 16 + 1 ) + 5; 436 // prng( 5, 21 ); 437 405 438 void set_seed( uint32_t seed_ ) OPTIONAL_THREAD; 406 uint32_t get_seed() __attribute__(( warn_unused_result )) ;439 uint32_t get_seed() __attribute__(( warn_unused_result )) OPTIONAL_THREAD; 407 440 uint32_t prng( void ) __attribute__(( warn_unused_result )) OPTIONAL_THREAD; // [0,UINT_MAX] 408 441 static inline {
Note: See TracChangeset
for help on using the changeset viewer.