Logo ROOT  
Reference Guide
MixMaxEngine.icc
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: L. Moneta 8/2015
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2015 , ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// implementation file of MixMax engine
12//
13//
14// Created by: Lorenzo Moneta : Tue 4 Aug 2015
15//
16//
17#ifndef ROOT_Math_MixMaxEngine_icc
18#define ROOT_Math_MixMaxEngine_icc
19
20#ifndef ROOT_Math_MixMaxEngine
21#error "Do not use MixMaxEngine.icc directly. #include \"MixMaxEngine.h\" instead."
22#endif // ROOT_Math_MixMaxEngine
23
24//#include "Math/mixmax/mixmax.h"
25#include <cassert>
26#include "Math/Util.h"
27
28
29namespace ROOT {
30namespace Math {
31
32
33
34 template<int N, int S>
36 // fRng = new mixmax::mixmax_engine<N>();
37 // fRng->seed(seed);
38 fRng = new MixMaxEngineImpl<N>(seed);
39 }
40
41 template<int N, int S>
43 if (fRng) delete fRng;
44 }
45
46
47 // void template<int N, int S>
48 //MixMaxEngine<N,S>::SeedUniqueStream(unsigned int clusterID, unsigned int machineID, unsigned int runID, unsigned int streamID) {
49 // seed_uniquestream(fRngState, clusterID, machineID, runID, streamID);
50 // }
51
52 template<int N, int S>
53 void MixMaxEngine<N,S>::SetSeed(uint64_t seed) {
54 //fRng->seed(seed);
55 fRng->SetSeed(seed);
56 }
57
58 // void template<int N, int S>
59 // MixMaxEngine<N,S>::SetSeed64(uint64_t seed) {
60 // seed_spbox(fRngState, seed);
61 // iterate(fRngState);
62 // }
63
64 // unsigned int template<int N, int S>
65 // MixMaxEngine<N,S>::GetSeed() const {
66 // return get_next(fRngState);
67 // }
68
69 // generate one random number in interval ]0,1]
70 // apply skipping when needed
71
72 template<int SkipNumber>
73 struct SkipFunction {
74 template<class Engine>
75 static void Apply (Engine * rng, int counter, int n) {
76 // apply skipping
77 if (counter < n) return;
78 for (int iskip = 0; iskip < SkipNumber; ++iskip)
79 rng->Iterate();
80 }
81 };
82 // specialization for SkipNumber = 0
83 template<>
84 struct SkipFunction<0> {
85 template<class Engine>
86 static void Apply (Engine *, int , int ) {
87 // no operation
88 }
89 };
90
91 template<int N, int S>
93 int counter = fRng->Counter();
94 SkipFunction<S>::Apply(fRng, counter, N);
95 //reset counter to original value
96 // otherwise we would skip -1 time
97 fRng->SetCounter(counter);
98 return fRng->Rndm();
99 }
100
101 // generate one integer number
102 template<int N, int S>
104 int counter = fRng->Counter();
105 SkipFunction<S>::Apply(fRng, counter,N);
106 fRng->SetCounter(counter);
107 return fRng->IntRndm();
108 }
109
110 template<int N, int S>
112 //return mixmax::mixmax_engine<N>::max();
113 return 2305843009213693951ULL;
114 }
115
116 template<int N, int S>
118 //return mixmax::mixmax_engine<N>::min();
119 return 0;
120 }
121
122 template<int N, int S>
123 void MixMaxEngine<N,S>::RndmArray(int n, double *array){
124 // Return an array of n random numbers uniformly distributed in ]0,1]
125 for (int i = 0; i < n; ++i)
126 array[i] = Rndm_impl();
127 }
128
129 template<int N, int S>
130 void MixMaxEngine<N,S>::SetState(const std::vector<StateInt_t> & state) {
131 assert(state.size() >= N);
132 // for (int i = 0; i < N; ++i)
133 // fRng->S.V[i] = state[i];
134 // //set counter to fore iteration afterwards
135 // fRng->S.counter = N;
136 fRng->SetState(state);
137 fRng->SetCounter(N);
138 }
139
140 template<int N, int S>
141 void MixMaxEngine<N,S>::GetState(std::vector<StateInt_t> & state) const {
142 state.resize(N);
143 fRng->GetState(state);
144 }
145
146 template<int N, int S>
149 }
150
151 template<int N, int S>
153 return fRng->Counter();
154 }
155
156 template<int N, int S>
158 static const std::string name = "MixMax" + Util::ToString(N) + (S > 0 ? "_" + Util::ToString(S) : "");
159 return name.c_str();
160 }
161
162 } // namespace Math
163} // namespace ROOT
164
165#endif
#define N
char name[80]
Definition: TGX11.cxx:109
Result_t IntRndm()
generate a 64 bit integer number
void GetState(std::vector< StateInt_t > &state) const
get the state of the generator
void SetSeed(Result_t seed)
set the generator seed
int Counter() const
Get the counter (between 0 and Size-1)
MixMaxEngine(uint64_t seed=1)
double Rndm_impl()
implementation function to generate the random number
static const char * Name()
get name of the generator
void RndmArray(int n, double *array)
generate an array of random numbers
void SetState(const std::vector< StateInt_t > &state)
set the full initial generator state
static int Size()
Get the size of the generator.
static uint64_t MaxInt()
maximum integer that can be generated. For MIXMAX is 2^61-1
static uint64_t MinInt()
minimum integer that can be generated. For MIXMAX is 0
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
std::string ToString(const T &val)
Utility function for conversion to strings.
Definition: Util.h:50
VSD Structures.
Definition: StringConv.hxx:21
RooArgSet S(const RooAbsArg &v1)
const char * Size
Definition: TXMLSetup.cxx:55
static void Apply(Engine *, int, int)
static void Apply(Engine *rng, int counter, int n)