File Coverage

src/pcg.c
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 13 13 100.0


line stmt bran cond sub pod time code
1             /* *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
2             * Licensed under Apache License 2.0 (NO WARRANTY, etc. see website) */
3              
4             #include
5             #include
6              
7             #include "pcg.h"
8              
9 76           uint32_t pcg32_random_r(pcg32_random_t * rng)
10             {
11 76           uint64_t oldstate = rng->state;
12             // Advance internal state
13 76           rng->state = oldstate * 6364136223846793005ULL + (rng->inc | 1);
14             // Calculate output function (XSH RR), uses old state for max ILP
15 76           uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
16 76           uint32_t rot = oldstate >> 59u;
17 76           return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
18             }
19              
20 1           void pcg32_srandom_r(pcg32_random_t * rng, uint64_t initstate, uint64_t initseq)
21             {
22 1           rng->state = 0U;
23 1           rng->inc = (initseq << 1u) | 1u;
24 1           pcg32_random_r(rng);
25 1           rng->state += initstate;
26 1           pcg32_random_r(rng);
27 1           }