1 #include "icemc_random.h" 5 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,8,0) 6 #include "TRandomGen.h" 19 static ULong_t next_ran_splitmix64(ULong_t x)
21 ULong_t z = (x += 0x9e3779b97f4a7c15);
22 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
23 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
28 static inline ULong_t rotl(
const ULong_t x,
int k)
30 return (x << k) | (x >> (64-k));
37 ULong_t TRandomXoshiro256Plus::RawRndm()
39 const ULong_t t = fState[1] << 17;
40 fState[2] ^= fState[0];
41 fState[3] ^= fState[1];
42 fState[1] ^= fState[2];
43 fState[0] ^= fState[3];
45 fState[3] = rotl(fState[3],45);
47 return fState[0] + fState[3];
50 Double_t TRandomXoshiro256Plus::Rndm()
52 const Double_t inv_max = 1./(1ull << 53);
53 return (RawRndm() >> 11) * inv_max;
56 void TRandomXoshiro256Plus::SetSeed(ULong_t seed)
61 uuid.GetUUID( (UChar_t*) fState);
63 uuid2.GetUUID( ((UChar_t*) fState) + 16);
67 fState[0] = next_ran_splitmix64(seed);
68 fState[1] = next_ran_splitmix64(fState[0]);
69 fState[2] = next_ran_splitmix64(fState[1]);
70 fState[3] = next_ran_splitmix64(fState[2]);
76 void TRandomXoshiro256Plus::RndmArray(Int_t n, Float_t * arr)
78 const Float_t inv_max = 1./(1ul << 24);
79 for (Int_t i = 0; i < n/2; i++)
81 arr[2*i] = ((RawRndm() >> 16) & 0xffffff) *inv_max;
82 arr[2*i+1] = (RawRndm() >>40) *inv_max;
86 if (n % 2) arr[n-1] = (RawRndm() >>40) *inv_max;
90 void TRandomXoshiro256Plus::RndmArray(Int_t n, Double_t * arr)
92 const Double_t inv_max = 1./(1ull << 53);
93 for (Int_t i = 0; i < n; i++) arr[i] = (RawRndm()>>11) *inv_max;
99 static ULong_t the_seed = 12345;
100 static WhichIceMcRNGType the_rng_type;
101 static TRandom* rngs[HOW_MANY_RNGS_DO_WE_HAVE];
109 setRNGType(RNG_TYPE_XOSHIRO256PLUS);
116 WhichIceMcRNGType getRNGType() {
return the_rng_type; }
118 void setRNGType(WhichIceMcRNGType type)
122 for (
unsigned i = 0; i < HOW_MANY_RNGS_DO_WE_HAVE; i++)
124 if (rngs[i])
delete rngs[i];
127 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,8,0) 128 type == RNG_TYPE_MT64 ? (TRandom*)
new TRandomMT64 :
129 type == RNG_TYPE_MIXMAX256 ? (TRandom*)
new TRandomMixMax256 :
131 (TRandom*)
new TRandom3;
136 void setSeed(ULong_t s)
139 for (
unsigned i = 0; i <HOW_MANY_RNGS_DO_WE_HAVE; i++) rngs[i]->SetSeed(s + i * 1235);
143 TRandom * getRNG(WhichIceMcRNG w)