Logo ROOT  
Reference Guide
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 #include <string>
46 
47 template<class Engine>
48 class TRandomGen : public TRandom {
49 
50 protected:
51 
52  Engine fEngine; // random number generator engine
53 public:
54 
55  TRandomGen(ULong_t seed=1) {
56  fEngine.SetSeed(seed);
57  SetName(TString::Format("Random_%s", std::string(fEngine.Name()).c_str()));
58  SetTitle(TString::Format("Random number generator: %s", std::string(fEngine.Name()).c_str()));
59  }
60  virtual ~TRandomGen() {}
61  using TRandom::Rndm;
62  virtual Double_t Rndm( ) { return fEngine(); }
63  virtual void RndmArray(Int_t n, Float_t *array) {
64  for (int i = 0; i < n; ++i) array[i] = fEngine();
65  }
66  virtual void RndmArray(Int_t n, Double_t *array) {
67  for (int i = 0; i < n; ++i) array[i] = fEngine();
68  }
69  virtual void SetSeed(ULong_t seed=0) {
70  fEngine.SetSeed(seed);
71  }
72 
73  ClassDef(TRandomGen,1) //Generic Random number generator template on the Engine type
74 };
75 
76 // some useful typedef
77 #include "Math/StdEngine.h"
78 #include "Math/MixMaxEngine.h"
79 
80 // not working wight now for this classes
81 //#define DEFINE_TEMPL_INSTANCE
82 #ifdef DEFINE_TEMPL_INSTANCE
83 
84 extern template class TRandomGen<ROOT::Math::MixMaxEngine<240,0>>;
85 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,2>>;
86 extern template class TRandomGen<ROOT::Math::MixMaxEngine<256,4>>;
87 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,0>>;
88 extern template class TRandomGen<ROOT::Math::MixMaxEngine<17,1>>;
89 
92 
93 #endif
94 /**
95  @ingroup Random
96  MIXMAX generator based on a state of N=240.
97  This generator is described in this paper:
98 
99  K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
100  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
101  */
103 
104 /**
105  @ingroup Random
106  MIXMAX generator based on a state of N=17. This generator has a fast seeding time
107  compared to N=240.
108  This generator is described in this paper:
109 
110  K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
111  Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
112  */
114 
115 /**
116  @ingroup Random
117  MIXMAX generator based on a state of N=256, based on the generator descrived in this
118  paper:
119 
120  K. Savvidy, *The MIXMAX random number generator*, Comp. Phys. Commun. 196 (2015), pp 161–165
121  http://dx.doi.org/10.1016/j.cpc.2015.06.003
122 
123  This generator has been implemented with a skipping value of 2 iterations (so retaining one
124  matrix iteration every 3).
125 
126  */
128 /**
129  @ingroup Random
130  Generator based on a the Mersenne-Twister generator with 64 bits,
131  using the implementation provided by the standard library,
132  std::mt19937_64 (see http://www.cplusplus.com/reference/random/mt19937_64/ )
133 
134  */
136 /**
137  @ingroup Random
138  Generator based on a the RanLux generator with 48 bits,
139  using the implementation provided by the standard library,
140  std::ranlux48 (see http://www.cplusplus.com/reference/random/ranlux48/ )
141 
142  */
144 
145 
146 #endif
n
const Int_t n
Definition: legend1.C:16
TRandomGen::RndmArray
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition: TRandomGen.h:69
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
MixMaxEngine.h
TRandomGen::fEngine
Engine fEngine
Definition: TRandomGen.h:58
TRandomMixMax17
TRandomGen< ROOT::Math::MixMaxEngine< 17, 0 > > TRandomMixMax17
Definition: TRandomGen.h:113
TRandom.h
Float_t
float Float_t
Definition: RtypesCore.h:57
Int_t
int Int_t
Definition: RtypesCore.h:45
TString::Format
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
TRandomGen::TRandomGen
TRandomGen(ULong_t seed=1)
Definition: TRandomGen.h:61
StdEngine.h
TRandom
Definition: TRandom.h:27
TRandomMixMax256
TRandomGen< ROOT::Math::MixMaxEngine< 256, 2 > > TRandomMixMax256
Definition: TRandomGen.h:127
TRandom::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
TRandomGen::~TRandomGen
virtual ~TRandomGen()
Definition: TRandomGen.h:66
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TRandomMixMax
TRandomGen< ROOT::Math::MixMaxEngine< 240, 0 > > TRandomMixMax
Definition: TRandomGen.h:102
Double_t
double Double_t
Definition: RtypesCore.h:59
TRandomMT64
TRandomGen< ROOT::Math::StdEngine< std::mt19937_64 > > TRandomMT64
Definition: TRandomGen.h:135
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TRandomGen
Definition: TRandomGen.h:48
TRandomRanlux48
TRandomGen< ROOT::Math::StdEngine< std::ranlux48 > > TRandomRanlux48
Definition: TRandomGen.h:143
TRandomGen::Rndm
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandomGen.h:68
TRandomGen::SetSeed
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandomGen.h:75
int