textual
[RRG-proxmark3.git] / client / src / prng.c
blobfe582205f596ac602dbd030a9cf049535828ad7a
1 //-----------------------------------------------------------------------------
2 //-----------------------------------------------------------------------------
3 // Burtle Prng - Modified. 42iterations instead of 20.
4 // ref: http://burtleburtle.net/bob/rand/smallprng.html
5 //-----------------------------------------------------------------------------
6 #include "prng.h"
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;
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);
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);
35 uint32_t GetSimplePrng(uint32_t seed) {
36 seed *= 0x19660D;
37 seed += 0x3C6EF35F;
38 return seed;