]>
Commit | Line | Data |
---|---|---|
bf5d7992 | 1 | #include "random.h" |
2 | ||
e99acd00 | 3 | static uint32_t g_nextrandom; |
bf5d7992 | 4 | |
5 | /* Generates a (non-cryptographically secure) 32-bit random number. | |
6 | * | |
7 | * We don't have an implementation of the "rand" function. Instead we use a | |
8 | * method of seeding with the time it took to call "autoseed" from first run. | |
9 | * | |
10 | * https://github.com/Proxmark/proxmark3/pull/209/commits/f9c1dcd9f6e68a8c07cffed697a9c4c8caed6015 | |
e99acd00 | 11 | * |
12 | * Iceman, rand needs to be fast. | |
13 | * https://software.intel.com/en-us/articles/fast-random-number-generator-on-the-intel-pentiumr-4-processor/ | |
bf5d7992 | 14 | */ |
e99acd00 | 15 | |
16 | inline void fast_prand(){ | |
17 | fast_prandEx(GetTickCount()); | |
18 | } | |
19 | inline void fast_prandEx(uint32_t seed) { | |
20 | g_nextrandom = seed; | |
21 | } | |
22 | ||
bf5d7992 | 23 | uint32_t prand() { |
e99acd00 | 24 | // g_nextrandom *= 6364136223846793005; |
25 | // g_nextrandom += 1; | |
26 | //return (uint32_t)(g_nextrandom >> 32) % 0xffffffff; | |
27 | g_nextrandom = (214013 * g_nextrandom + 2531011); | |
28 | return (g_nextrandom>>16) & 0xFFFF; | |
bf5d7992 | 29 | } |
30 |