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