rng.h 439 B

123456789101112131415161718192021
  1. #ifndef __RNG_H
  2. #define __RNG_H
  3. // RNG parameters, defaults taken from drand48
  4. #define RNG_A __UINT64_C(0x5DEECE66D)
  5. #define RNG_C __UINT64_C(0xB)
  6. #define RNG_M ((__UINT64_C(1) << 48) - 1)
  7. // Same as drand48, but inlined for efficiency
  8. inline UInt64 rng_next(UInt64 &state)
  9. {
  10. state = (RNG_A * state + RNG_C) & RNG_M;
  11. return state >> 16;
  12. }
  13. inline UInt64 rng_seed(UInt64 seed)
  14. {
  15. return (seed << 16) + 0x330E;
  16. }
  17. #endif // __RNG_H