Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //The following RNG is based on code for the xorshift* RNG by Sebastiano Vigna
  2. //Parameters are chosen from the original paper such to
  3.  
  4. typedef struct
  5. {
  6.     uint64_t w, x;
  7. } XorShift128rm_state;
  8.  
  9. const uint64_t p1 = 0x243f6a8885a308d3;
  10. const uint64_t p2 = 0x13198a2e03707345;
  11.  
  12. static uint64_t rotl(uint64_t x, uint8_t r)
  13. {
  14.     return (x << r) | (x >> (64-r));
  15. }
  16.  
  17. uint64_t XorShift128rm(XorShift128rm_state *s)
  18. {
  19.     uint64_t t = s->w;
  20.     s->w = s->x;
  21.     s->x = t;
  22.  
  23.     s->x ^= s->x << 16;
  24.     s->x ^= (s->x >> 21) ^ s->w ^ (s->w >> 1);
  25.  
  26.     return rotl(s->x*p1, 16)*p2;
  27. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement