]>
Commit | Line | Data |
---|---|---|
1 | //----------------------------------------------------------------------------- | |
2 | //----------------------------------------------------------------------------- | |
3 | // Burtle Prng - Modified. 42iterations instead of 20. | |
4 | // ref: http://burtleburtle.net/bob/rand/smallprng.html | |
5 | //----------------------------------------------------------------------------- | |
6 | #include "prng.h" | |
7 | ||
8 | #define rot(x,k) (((x)<<(k))|((x)>>(32-(k)))) | |
9 | uint32_t burtle_get_mod( prng_ctx *x ) { | |
10 | uint32_t e = x->a - rot(x->b, 21); | |
11 | x->a = x->b ^ rot(x->c, 19); | |
12 | x->b = x->c + rot(x->d, 6); | |
13 | x->c = x->d + e; | |
14 | x->d = e + x->a; | |
15 | return x->d; | |
16 | } | |
17 | ||
18 | void burtle_init_mod(prng_ctx *x, uint32_t seed ) { | |
19 | x->a = 0xf1ea5eed; | |
20 | x->b = x->c = x->d = seed; | |
21 | for (uint8_t i=0; i < 42; ++i) { | |
22 | (void)burtle_get_mod(x); | |
23 | } | |
24 | } | |
25 | ||
26 | void burtle_init(prng_ctx *x, uint32_t seed ) { | |
27 | uint32_t i; | |
28 | x->a = 0xf1ea5eed, x->b = x->c = x->d = seed; | |
29 | for (i=0; i < 20; ++i) { | |
30 | (void)burtle_get_mod(x); | |
31 | } | |
32 | } | |
33 | ||
34 | ||
35 | uint32_t GetSimplePrng( uint32_t seed ){ | |
36 | seed *= 0x19660D; | |
37 | seed += 0x3C6EF35F; | |
38 | return seed; | |
39 | } |