Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
47template<class Engine>
48class TRandomGen : public TRandom {
49
50protected:
51
52 Engine fEngine; // random number generator engine
53public:
54
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#include "Math/RanluxppEngine.h"
80
81// not working wight now for this classes
82//#define DEFINE_TEMPL_INSTANCE
83#ifdef DEFINE_TEMPL_INSTANCE
84
90
92
95
96#endif
97/**
98 @ingroup Random
99 MIXMAX generator based on a state of N=240.
100 This generator is described in this paper:
101
102 K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
103 Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
104 */
106
107/**
108 @ingroup Random
109 MIXMAX generator based on a state of N=17. This generator has a fast seeding time
110 compared to N=240.
111 This generator is described in this paper:
112
113 K. Savvidy and G. Savvidy, *Spectrum and Entropy of C-systems. MIXMAX random number generator*,
114 Chaos, Solitons & Fractals, Volume 91, (2016) pp. 33–38 http://dx.doi.org/10.1016/j.chaos.2016.05.003
115 */
117
118/**
119 @ingroup Random
120 MIXMAX generator based on a state of N=256, based on the generator descrived in this
121 paper:
122
123 K. Savvidy, *The MIXMAX random number generator*, Comp. Phys. Commun. 196 (2015), pp 161–165
124 http://dx.doi.org/10.1016/j.cpc.2015.06.003
125
126 This generator has been implemented with a skipping value of 2 iterations (so retaining one
127 matrix iteration every 3).
128
129 */
131
133
134/**
135 @ingroup Random
136 Generator based on a the Mersenne-Twister generator with 64 bits,
137 using the implementation provided by the standard library,
138 std::mt19937_64 (see http://www.cplusplus.com/reference/random/mt19937_64/ )
139
140 */
142/**
143 @ingroup Random
144 Generator based on a the RanLux generator with 48 bits,
145 using the implementation provided by the standard library,
146 std::ranlux48 (see http://www.cplusplus.com/reference/random/ranlux48/ )
147
148 */
150
151
152#endif
unsigned long ULong_t
Definition RtypesCore.h:55
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
#define ClassDef(name, id)
Definition Rtypes.h:325
TRandomGen< ROOT::Math::RanluxppEngine2048 > TRandomRanluxpp
Definition TRandomGen.h:132
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:62
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition TRandomGen.h:63
Engine fEngine
Definition TRandomGen.h:52
virtual void RndmArray(Int_t n, Double_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
Definition TRandomGen.h:66
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandomGen.h:69
virtual ~TRandomGen()
Definition TRandomGen.h:60
TRandomGen(ULong_t seed=1)
Definition TRandomGen.h:55
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:552
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:2336
TRandomGen< ROOT::Math::MixMaxEngine< 240, 0 > > TRandomMixMax
MIXMAX generator based on a state of N=240.
Definition TRandomGen.h:105
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:141
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:130
TRandomGen< ROOT::Math::MixMaxEngine< 17, 0 > > TRandomMixMax17
MIXMAX generator based on a state of N=17.
Definition TRandomGen.h:116
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:149
const Int_t n
Definition legend1.C:16