1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include "pcg_basic.h"
- void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initial_state, uint64_t initseq) {
- rng->state = 0U;
- rng->inc = (initseq << 1u) | 1u;
- pcg32_random_r(rng);
- rng->state += initial_state;
- pcg32_random_r(rng);
- }
- uint32_t pcg32_random_r(pcg32_random_t* rng) {
- uint64_t oldstate = rng->state;
- rng->state = oldstate * 6364136223846793005ULL + rng->inc;
- uint32_t xorshifted = (uint32_t)(((oldstate >> 18u) ^ oldstate) >> 27u);
- uint32_t rot = (uint32_t)(oldstate >> 59u);
- return (xorshifted >> rot) | (xorshifted << ((~rot + 1u) & 31));
- }
|