Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lightweight adaptation of the example multiply with carry PRNG
- * code from wikipedia
- * Version: 1
- */
- #include <stdint.h>
- #define PHI 0x9e3779b9
- static uint32_t Q, c = 362436;
- void init_rand(uint32_t x)
- { Q = x;
- }
- uint32_t rand_cmwc(void)
- { uint64_t t, a = 18782LL;
- uint32_t x, r = 0xfffffffe;
- t = a * Q + c;
- c = (t >> 32);
- x = t + c;
- if(x < c)
- { x++;
- c++;
- }
- return (Q = r - x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement