src/jsf.c

filter: Statementstmt 100% 12 / 12 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 14 / 14 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/Game/Xomb.xs ↑ Summary
1 /* Jenkins Small Fast -- "A small noncryptographic PRNG"
2 * http://burtleburtle.net/bob/rand/smallprng.html
3 * https://www.pcg-random.org/posts/some-prng-implementations.html */
4  
5 #include <stdint.h>
6  
7 #include "jsf.h"
8  
9 #define rot32(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
10  
11 struct ranctx {
12 uint32_t a;
13 uint32_t b;
14 uint32_t c;
15 uint32_t d;
16 };
17  
18 struct ranctx ctx;
19  
20 106 void raninit(uint32_t seed) {
21 uint32_t i;
22 106 ctx.a = 0xf1ea5eed, ctx.b = ctx.c = ctx.d = seed;
23 2226 ▶ for (i = 0; i < 20; ++i)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 20; ++i) 2120 106 2226
24 2120 ranval();
25 106 }
26  
27 31397 uint32_t ranval(void) {
28 31397 uint32_t e = ctx.a - rot32(ctx.b, 27);
29 31397 ctx.a = ctx.b ^ rot32(ctx.c, 17);
30 31397 ctx.b = ctx.c + ctx.d;
31 31397 ctx.c = ctx.d + e;
32 31397 ctx.d = e + ctx.a;
33 31397 return ctx.d;
34 }
« lib/Game/Xomb.xs ↑ Summary