changa 3.5
Loading...
Searching...
No Matches
rand.h
1#ifndef RAND_HINCLUDED
2#define RAND_HINCLUDED
3
8class Rand
9{
10 private:
11 u_int64_t u,v,w; /* State holders */
12 public:
13 Rand(u_int64_t j = 0 /* Seed */
14 ) : v(4101842887655102017LL), w(1) {
15 u = j ^ v; int64();
16 v = u; int64();
17 w = v; int64();
18 }
21 inline u_int64_t int64() {
22 u = u * 2862933555777941757LL + 7046029254386353087LL;
23 v ^= v >> 17; v ^= v << 31; v ^= v >> 8;
24 w = 4294957665U*(w & 0xffffffff) + (w >> 32);
25 u_int64_t x = u ^ (u << 21); x ^= x >> 35; x ^= x << 4;
26 return (x + v) ^ w;
27 }
28
30 inline double dbl() {
31 const double iRANDMAX = 5.42101086242752217E-20;
32 return iRANDMAX * int64();
33 }
34
36 inline u_int32_t int32() { return (u_int32_t)int64(); }
37#ifdef __CHARMC__
38 inline void pup(PUP::er &p) {
39 p|u;
40 p|v;
41 p|w;
42 }
43#endif
44};
45
46#endif // RAND_HINCLUDED
u_int32_t int32()
return 32 bit random number
Definition rand.h:36
double dbl()
return random double 0<x<1
Definition rand.h:30
u_int64_t int64()
return 64 bit random number
Definition rand.h:21