]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - common/prng.c
1 //-----------------------------------------------------------------------------
2 //-----------------------------------------------------------------------------
3 // Burtle Prng - Modified. 42iterations instead of 20.
4 // ref: http://burtleburtle.net/bob/rand/smallprng.html
5 //-----------------------------------------------------------------------------
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);
18 void burtle_init_mod(prng_ctx
*x
, uint32_t seed
) {
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
) {
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
){