Logo ROOT   6.18/05
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
45template<class Engine>
46class TRandomGen : public TRandom {
47
48protected:
49
50 Engine fEngine; // random number generator engine
51public:
52
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
87
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 */
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 */
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 */
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 */
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 */
142
143
144#endif
int Int_t
Definition: RtypesCore.h:41
unsigned long ULong_t
Definition: RtypesCore.h:51
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
#define ClassDef(name, id)
Definition: Rtypes.h:326
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandomGen.h:60
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition: TRandomGen.h:61
Engine fEngine
Definition: TRandomGen.h:50
virtual void RndmArray(Int_t n, Double_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition: TRandomGen.h:64
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandomGen.h:67
virtual ~TRandomGen()
Definition: TRandomGen.h:58
TRandomGen(ULong_t seed=1)
Definition: TRandomGen.h:53
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:541
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< ROOT::Math::MixMaxEngine< 240, 0 > > TRandomMixMax
MIXMAX generator based on a state of N=240.
Definition: TRandomGen.h:100
TRandomGen< ROOT::Math::StdEngine< std::mt19937_64 > > TRandomMT64
Generator based on a the Mersenne-Twister generator with 64 bits, using the implementation provided b...
Definition: TRandomGen.h:133
TRandomGen< ROOT::Math::MixMaxEngine< 256, 2 > > TRandomMixMax256
MIXMAX generator based on a state of N=256, based on the generator descrived in this paper:
Definition: TRandomGen.h:125
TRandomGen< ROOT::Math::MixMaxEngine< 17, 0 > > TRandomMixMax17
MIXMAX generator based on a state of N=17.
Definition: TRandomGen.h:111
TRandomGen< ROOT::Math::StdEngine< std::ranlux48 > > TRandomRanlux48
Generator based on a the RanLux generator with 48 bits, using the implementation provided by the stan...
Definition: TRandomGen.h:141
const Int_t n
Definition: legend1.C:16