Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRandom.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: Rene Brun 15/12/95
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_TRandom
13#define ROOT_TRandom
14
15#include "Math/TRandomEngine.h"
16
17//////////////////////////////////////////////////////////////////////////
18// //
19// TRandom //
20// //
21// Simple prototype random number generator class (periodicity = 10**9) //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include "TNamed.h"
26#include <limits>
27
29
30protected:
31 UInt_t fSeed; //Random number generator seed
32
33public:
34 TRandom(UInt_t seed=65539);
35 ~TRandom() override;
37 virtual Double_t BreitWigner(Double_t mean=0, Double_t gamma=1);
38 virtual void Circle(Double_t &x, Double_t &y, Double_t r);
39 virtual Double_t Exp(Double_t tau);
40 virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1);
41 virtual UInt_t GetSeed() const;
42 virtual UInt_t Integer(UInt_t imax);
43 virtual Double_t Landau(Double_t mean=0, Double_t sigma=1);
44 virtual ULong64_t Poisson(Double_t mean);
45 virtual Double_t PoissonD(Double_t mean);
46 virtual void Rannor(Float_t &a, Float_t &b);
47 virtual void Rannor(Double_t &a, Double_t &b);
48 virtual void ReadRandom(const char *filename);
49 virtual void SetSeed(ULong_t seed=0);
50 Double_t Rndm() override;
51 // keep for backward compatibility
52 virtual Double_t Rndm(Int_t ) { return Rndm(); }
53 virtual void RndmArray(Int_t n, Float_t *array);
54 virtual void RndmArray(Int_t n, Double_t *array);
55 virtual void Sphere(Double_t &x, Double_t &y, Double_t &z, Double_t r);
56 virtual Double_t Uniform(Double_t x1=1);
58 virtual void WriteRandom(const char *filename) const;
59
60 // std::UniformRandomBitGenerator interface -- makes TRandom usable directly
61 // with std::shuffle, std::uniform_int_distribution and similar.
63 static constexpr result_type min() { return 0; }
64 static constexpr result_type max() { return std::numeric_limits<UInt_t>::max(); }
65 /// \note Rndm() returns a double in ]0,1[, so converting back to UInt_t
66 /// has a small precision loss. Subclasses with access to raw integer output
67 /// should override this for better accuracy.
68 virtual result_type operator()() { return static_cast<result_type>(Rndm() * (static_cast<double>(max()) + 1.0)); }
69
70 ClassDefOverride(TRandom,3) //Simple Random number generator (periodicity = 10**9)
71};
72
74
75#endif
#define R__EXTERN
Definition DllImport.h:26
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int)
Definition RtypesCore.h:60
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
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
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
R__EXTERN TRandom * gRandom
Definition TRandom.h:73
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
This is the base class for the ROOT Random number generators.
Definition TRandom.h:28
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:274
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1[.
Definition TRandom.cxx:594
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:614
virtual void WriteRandom(const char *filename) const
Writes random generator status to filename.
Definition TRandom.cxx:699
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:558
UInt_t fSeed
Definition TRandom.h:31
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:506
virtual Double_t PoissonD(Double_t mean)
Generates a random number according to a Poisson law.
Definition TRandom.cxx:460
virtual void ReadRandom(const char *filename)
Reads saved random generator status from filename.
Definition TRandom.cxx:536
virtual UInt_t GetSeed() const
Get the random generator seed.
Definition TRandom.cxx:650
virtual ULong64_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
Definition TRandom.cxx:403
static constexpr result_type min()
Definition TRandom.h:63
virtual Double_t Exp(Double_t tau)
Returns an exponential deviate.
Definition TRandom.cxx:251
virtual void Circle(Double_t &x, Double_t &y, Double_t r)
Generates random vectors, uniformly distributed over a circle of given radius.
Definition TRandom.cxx:239
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition TRandom.cxx:681
virtual void Sphere(Double_t &x, Double_t &y, Double_t &z, Double_t r)
Generates random vectors, uniformly distributed over the surface of a sphere of given radius.
Definition TRandom.cxx:663
virtual Double_t Landau(Double_t mean=0, Double_t sigma=1)
Generate a random number following a Landau distribution with location parameter mu and scale paramet...
Definition TRandom.cxx:380
TRandom(UInt_t seed=65539)
Default constructor. For seed see SetSeed().
Definition TRandom.cxx:186
virtual Int_t Binomial(Int_t ntot, Double_t prob)
Generates a random integer N according to the binomial law.
Definition TRandom.cxx:211
virtual Double_t BreitWigner(Double_t mean=0, Double_t gamma=1)
Return a number distributed following a BreitWigner function with mean and gamma.
Definition TRandom.cxx:225
~TRandom() override
Default destructor.
Definition TRandom.cxx:195
virtual Double_t Rndm(Int_t)
Definition TRandom.h:52
virtual result_type operator()()
Definition TRandom.h:68
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:360
static constexpr result_type max()
Definition TRandom.h:64
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