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: 2
- */
- #include <stdint.h>
- #define MWC_A 18782LL
- #define MWC_R 0xfffffffe
- static uint32_t Q, c = 362436;
- void init_rand(uint32_t x)
- { Q = x;
- }
- uint32_t rand_cmwc(void)
- { uint32_t x;
- uint64_t t = MWC_A * Q + c;
- c = (t >> 32);
- x = t + c;
- if(x < c)
- { x++;
- c++;
- }
- return (Q = MWC_R - x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement