src/pcg.c

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 13 / 13 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Math/Random/PCG32.pm ↑ Summary
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 <EXTERN.h>
5 #include <perl.h>
6  
7 #include "pcg.h"
8  
9 81 uint32_t pcg32_random_r(pcg32_random_t * rng)
10 {
11 81 uint64_t oldstate = rng->state;
12 // Advance internal state
13 81 rng->state = oldstate * 6364136223846793005ULL + (rng->inc | 1);
14 // Calculate output function (XSH RR), uses old state for max ILP
15 81 uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
16 81 uint32_t rot = oldstate >> 59u;
17 81 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 }
« blib/lib/Math/Random/PCG32.pm ↑ Summary