Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TRandomGen.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: Rene Brun 04/03/99
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TRandomGen
13 #define ROOT_TRandomGen
14 
15 
16 
17 //////////////////////////////////////////////////////////////////////////
18 // //
19 // TRandomGen
20 // @ingroup Random
21 // //
22 // Generic random number generator class which is template on the type //
23 // of engine. Using this class different random number generator all //
24 // implementing the TRandom interface can be built. //
25 // The available random number engine that can be presently used are //
26 // * ROOT::Math::MixMaxEngine to create random number generators //
27 // based on the MIXMAX family of generators. Different generators //
28 // can be created for different state N. //
29 // * ROOT::MATH::StdEngine to create genersators based on engines //
30 // provided by the C++ standard libraries
31 //
32 // Convenient typedef are defines to define the different types of
33 // generators. These typedef are
34 // * TRandomMixMax for the MixMaxEngine<240,0> (MIXMAX with state N=240)
35 // * TRandomMixMax17 for the MixMaxEngine<17,0> (MIXMAX with state N=17)
36 // * TRandomMixMax256 for the MixMaxEngine<256,2> (MIXMAX with state N=256 )
37 // * TRandomMT64 for the StdEngine<std::mt19937_64> ( MersenneTwister 64 bits)
38 // * TRandomRanlux48 for the StdEngine<std::ranlux48> (Ranlux 48 bits)
39 //
40 // //
41 //////////////////////////////////////////////////////////////////////////
42 
43 #include "TRandom.h"
44 
45 template<class Engine>
46 class TRandomGen : public TRandom {
47 
48 protected:
49 
50  Engine fEngine; // random number generator engine
51 public:
52 
53  TRandomGen(ULong_t seed=1) {
54  fEngine.SetSeed(seed);
55  SetName(TString::Format("Random_%s", std::string(fEngine.Name()).c_str()));
56  SetTitle(TString::Format("Random number generator: %s", std::string(fEngine.Name()).c_str()));
57  }
58  virtual ~TRandomGen() {}
59  using TRandom::Rndm;
60  virtual Double_t Rndm( ) { return fEngine(); }
61  virtual void RndmArray(Int_t n, Float_t *array) {
62  for (int i = 0; i < n; ++i) array[i] = fEngine();
63  }
64  virtual void RndmArray(Int_t n, Double_t *array) {
65  for (int i = 0; i < n; ++i) array[i] = fEngine();
66  }
67  virtual void SetSeed(ULong_t seed=0) {
68  fEngine.SetSeed(seed);
69  }
70 
71  ClassDef(TRandomGen,1) //Generic Random number generator template on the Engine type
72 };
73 
74 // some useful typedef
75 #include "Math/StdEngine.h"
76 #include "Math/MixMaxEngine.h"
77 
78 // not working wight now for this classes
79 //#define DEFINE_TEMPL_INSTANCE
80 #ifdef DEFINE_TEMPL_INSTANCE
81 
82 extern template class TRandomGen<ROOT::Math::MixMaxEngine<240,0>>;
83 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,2>>;
84 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,4>>;
85 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,0>>;
86 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,1>>;
87 
88 extern template class TRandomGen<ROOT::Math::StdEngine<std::mt19937_64> >;
89 extern template class TRandomGen<ROOT::Math::StdEngine<std::ranlux48> >;
90 
91 #endif
92 /**
93  @ingroup Random
94  MIXMAX generator based on a state of N=240.
95  This generator is described in this paper:
96 
97  K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
98  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
99  */
100 typedef TRandomGen<ROOT::Math::MixMaxEngine<240,0>> TRandomMixMax;
101 
102 /**
103  @ingroup Random
104  MIXMAX generator based on a state of N=17. This generator has a fast seeding time
105  compared to N=240.
106  This generator is described in this paper:
107 
108  K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
109  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
110  */
111 typedef TRandomGen<ROOT::Math::MixMaxEngine<17,0>> TRandomMixMax17;
112 
113 /**
114  @ingroup Random
115  MIXMAX generator based on a state of N=256, based on the generator descrived in this
116  paper:
117 
118  K. Savvidy, *The MIXMAX random number generator*, Comp. Phys. Commun. 196 (2015), pp 161–165
119  http://dx.doi.org/10.1016/j.cpc.2015.06.003
120 
121  This generator has been implemented with a skipping value of 2 iterations (so retaining one
122  matrix iteration every 3).
123 
124  */
125 typedef TRandomGen<ROOT::Math::MixMaxEngine<256,2>> TRandomMixMax256;
126 /**
127  @ingroup Random
128  Generator based on a the Mersenne-Twister generator with 64 bits,
129  using the implementation provided by the standard library,
130  std::mt19937_64 (see http://www.cplusplus.com/reference/random/mt19937_64/ )
131 
132  */
133 typedef TRandomGen<ROOT::Math::StdEngine<std::mt19937_64> > TRandomMT64;
134 /**
135  @ingroup Random
136  Generator based on a the RanLux generator with 48 bits,
137  using the implementation provided by the standard library,
138  std::ranlux48 (see http://www.cplusplus.com/reference/random/ranlux48/ )
139 
140  */
141 typedef TRandomGen<ROOT::Math::StdEngine<std::ranlux48> > TRandomRanlux48;
142 
143 
144 #endif