Logo ROOT  
Reference Guide
Random.h
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// Header file for random class
12//
13//
14// Created by: Lorenzo Moneta : Tue 4 Aug 2015
15//
16//
17#ifndef ROOT_Math_Random
18#define ROOT_Math_Random
19
20/**
21@defgroup Random Interface class for Random number generation
22*/
23
25
26#include <string>
27#include <vector>
28
29
30namespace ROOT {
31namespace Math {
32
33
34//___________________________________________________________________________________
35 /**
36 Documentation for the Random class
37
38 @ingroup Random
39 */
40
41 template < class Engine>
42 class Random {
43
44 public:
45
46 typedef typename Engine::BaseType EngineBaseType;
48
50 fEngine(),
52 {}
53
54 explicit Random(unsigned int seed) :
55 fEngine(),
57 {
58 fEngine.SetSeed(seed);
59 }
60
61 double Rndm() {
62 return fEngine();
63 }
64
65 /**
66 Generate an array of random numbers between ]0,1]
67 0 is excluded and 1 is included
68 Function to preserve ROOT Trandom compatibility
69 */
70 void RndmArray(int n, double * array) {
71 fEngine.RandomArray(array, array+n);
72 }
73
74 /**
75 Return the type (name) of the used generator
76 */
77 std::string Type() const {
78 return fEngine.Name();
79 }
80
81 /**
82 Return the size of the generator state
83 */
84 unsigned int EngineSize() const {
85 return fEngine.Size();
86 }
87
88
89 double operator() (){
90 return fEngine();
91 }
92
93 uint64_t Integer() {
94 return fEngine.IntRndm();
95 }
96
97 static uint64_t MaxInt() {
98 return Engine::Max();
99 }
100
101 Engine & Rng() {
102 return fEngine;
103 }
104
105 /// Exponential distribution
106 double Exp(double tau) {
107 return fFunctions.Exp(tau);
108 }
109
110 double Gaus(double mean = 0, double sigma = 1) {
111 return fFunctions.Gaus(mean,sigma);
112 }
113
114 /// Gamma distribution
115 double Gamma(double a, double b) {
116 return fFunctions.Gamma(a,b);
117 }
118
119 /// Beta distribution
120 double Beta(double a, double b) {
121 return fFunctions.Beta(a,b);
122 }
123
124 ///Log-normal distribution
125 double LogNormal(double zeta, double sigma) {
126 return fFunctions.LogNormal(zeta,sigma);
127 }
128
129 /// chi-square
130 double ChiSquare(double nu) {
131 return fFunctions.ChiSquare(nu);
132 }
133
134 /// Rayleigh distribution
135 double Rayleigh(double sigma) {
136 return fFunctions.Rayleigh(sigma);
137 }
138
139 /// Logistic distribution
140 double Logistic(double a) {
141 return fFunctions.Logistic(a);
142 }
143
144 /// Pareto distribution
145 double Pareto(double a, double b) {
146 return fFunctions.Pareto(a, b);
147 }
148
149 ///F-distribution
150 double FDist(double nu1, double nu2) {
151 return fFunctions.FDist(nu1,nu2);
152 }
153
154 /// t student distribution
155 double tDist(double nu) {
156 return fFunctions.tDist(nu);
157 }
158
159 /// Landau distribution
160 double Landau(double m = 0, double s = 1) {
161 return fFunctions.Landau(m,s);
162 }
163 /// Breit Wigner distribution
164 double BreitWigner(double mean = 0., double gamma = 1) {
165 return fFunctions.BreitWigner(mean,gamma);
166 }
167
168 /// generate random numbers in a 2D circle of radious 1
169 void Circle(double &x, double &y, double r = 1) {
170 fFunctions.Circle(x,y,r);
171 }
172
173 /// generate random numbers in a 3D sphere of radious 1
174 void Sphere(double &x, double &y, double &z,double r = 1) {
175 fFunctions.Sphere(x,y,z,r);
176 }
177
178
179 ///discrete distributions
180
181 /// Binomial distribution
182 unsigned int Binomial(unsigned int ntot, double prob) {
183 return fFunctions.Binomial(prob,ntot);
184 }
185
186
187 /// Poisson distribution
188 unsigned int Poisson(double mu) {
189 return fFunctions.Poisson(mu);
190 }
191
192 /// Negative Binomial distribution
193 /// First parameter is n, second is probability
194 /// To be consistent with Random::Binomial
195 unsigned int NegativeBinomial(double n, double prob) {
196 return fFunctions.NegativeBinomial(prob,n);
197 }
198
199 /// Multinomial distribution
200 std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
201 return fFunctions.Multinomial(ntot,p);
202 }
203
204
205
206 double Uniform(double a, double b) {
207 return fFunctions.Uniform(a,b);
208 }
209 double Uniform(double a = 1.0) {
210 return fFunctions.Uniform(a);
211 }
212 double Uniform2(double a, double b) {
213 return fFunctions.UniformBase(a,b);
214 }
215
216
218 return fFunctions;
219 }
220
221 void SetSeed(int seed) { fEngine.SetSeed(seed);}
222
223 private:
224
225 Engine fEngine; // random generator engine
226 RndmFunctions fFunctions; //! random functions object
227
228
229 };
230
231
232
233
234} // namespace Math
235} // namespace ROOT
236
237#include "Math/MixMaxEngine.h"
239#include "Math/StdEngine.h"
240
241namespace ROOT {
242namespace Math {
243
244 /// Useful typedef definitions
245
250
251} // namespace Math
252} // namespace ROOT
253
254
255#endif /* ROOT_Math_Random */
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
Documentation for the Random class.
Definition: Random.h:42
double Logistic(double a)
Logistic distribution.
Definition: Random.h:140
double Beta(double a, double b)
Beta distribution.
Definition: Random.h:120
Engine fEngine
Definition: Random.h:225
double tDist(double nu)
t student distribution
Definition: Random.h:155
double FDist(double nu1, double nu2)
F-distribution.
Definition: Random.h:150
double ChiSquare(double nu)
chi-square
Definition: Random.h:130
void Circle(double &x, double &y, double r=1)
generate random numbers in a 2D circle of radious 1
Definition: Random.h:169
unsigned int Poisson(double mu)
Poisson distribution.
Definition: Random.h:188
Engine & Rng()
Definition: Random.h:101
double Rayleigh(double sigma)
Rayleigh distribution.
Definition: Random.h:135
static uint64_t MaxInt()
Definition: Random.h:97
double Pareto(double a, double b)
Pareto distribution.
Definition: Random.h:145
Engine::BaseType EngineBaseType
Definition: Random.h:46
std::vector< unsigned int > Multinomial(unsigned int ntot, const std::vector< double > &p)
Multinomial distribution.
Definition: Random.h:200
std::string Type() const
Return the type (name) of the used generator.
Definition: Random.h:77
double Gamma(double a, double b)
Gamma distribution.
Definition: Random.h:115
RandomFunctions< Engine, EngineBaseType > RndmFunctions
Definition: Random.h:47
void RndmArray(int n, double *array)
Generate an array of random numbers between ]0,1] 0 is excluded and 1 is included Function to preserv...
Definition: Random.h:70
unsigned int Binomial(unsigned int ntot, double prob)
discrete distributions
Definition: Random.h:182
double LogNormal(double zeta, double sigma)
Log-normal distribution.
Definition: Random.h:125
void Sphere(double &x, double &y, double &z, double r=1)
generate random numbers in a 3D sphere of radious 1
Definition: Random.h:174
double Exp(double tau)
Exponential distribution.
Definition: Random.h:106
double BreitWigner(double mean=0., double gamma=1)
Breit Wigner distribution.
Definition: Random.h:164
double Uniform(double a, double b)
Definition: Random.h:206
double Uniform(double a=1.0)
Definition: Random.h:209
void SetSeed(int seed)
Definition: Random.h:221
double Landau(double m=0, double s=1)
Landau distribution.
Definition: Random.h:160
unsigned int NegativeBinomial(double n, double prob)
Negative Binomial distribution First parameter is n, second is probability To be consistent with Rand...
Definition: Random.h:195
Random(unsigned int seed)
Definition: Random.h:54
RndmFunctions fFunctions
Definition: Random.h:226
unsigned int EngineSize() const
Return the size of the generator state.
Definition: Random.h:84
double operator()()
Definition: Random.h:89
double Uniform2(double a, double b)
Definition: Random.h:212
double Rndm()
Definition: Random.h:61
RandomFunctions< Engine, EngineBaseType > & Functions()
Definition: Random.h:217
double Gaus(double mean=0, double sigma=1)
Definition: Random.h:110
uint64_t Integer()
Definition: Random.h:93
const Double_t sigma
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Namespace for new Math classes and functions.
double gamma(double x)
Random< ROOT::Math::StdEngine< std::mt19937_64 > > RandomMT64
Definition: Random.h:248
Random< ROOT::Math::StdEngine< std::ranlux48 > > RandomRanlux48
Definition: Random.h:249
Random< ROOT::Math::MixMaxEngine< 240, 0 > > RandomMixMax
Useful typedef definitions.
Definition: Random.h:246
Random< ROOT::Math::MersenneTwisterEngine > RandomMT19937
Definition: Random.h:247
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static constexpr double s
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:208
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12