3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
8 ///////////////////////////////////////////////////////////////////////////
10 // Generate universal random numbers on all common machines.
11 // Available distributions : Uniform, Gaussian, Poisson and
12 // User defined function
17 // 2) Same sequence of 24-bit real numbers on all common machines
21 // G.Marsaglia and A.Zaman, FSU-SCRI-87-50, Florida State University, 1987.
26 // Float_t rndm; // Variable to hold a single random number
27 // const Int_t n=1000;
28 // Float_t rvec[n]; // Vector to hold n random numbers
30 // AliRandom r; // Create a Random object with default sequence
32 // rndm=r.Uniform(); // Provide a uniform random number in <0,1>
35 // rndm=r.Uniform(a,b); // Provide a uniform random number in <a,b>
36 // r.Uniform(rvec,n); // Provide n uniform randoms in <0,1> in rvec
37 // r.Uniform(rvec,n,a,b); // Provide n uniform randoms in <a,b> in rvec
39 // rndm=r.Gauss(); // Provide a Gaussian random number with
40 // // mean=0 and sigma=1
43 // rndm=r.Gauss(mean,sigma); // Provide a Gaussian random number
44 // // with specified mean and sigma
45 // r.Gauss(rvec,n); // n Gaussian randoms mean=0 sigma=1
46 // r.Gauss(rvec,n,mean,sigma); // n Gaussian randoms with specified
49 // rndm=r.Poisson(mean); // Provide a Poisson random number with
51 // r.Poisson(rvec,nmean); // n Poisson randoms with specified mean
54 // AliRandom p(seed); // Create a Random object with specified seed.
55 // // The sequence is started from scratch.
58 // AliRandom q(seed,cnt1,cnt2); // Create a Random object with specified seed
59 // // The sequence is started at the location
60 // // denoted by the counters cnt1 and cnt2.
62 // q.Info(); // Print the current seed, cnt1 and cnt2 values.
63 // q.GetSeed(); // Provide the current seed value.
64 // q.GetCnt1(); // Provide the current cnt1 value.
65 // q.GetCnt2(); // Provide the current cnt2 value.
67 // Float_t udist(Float_t x) // A user defined distribution
73 // q.SetUser(a,b,nbins,udist); // Initialise generator for udist distribution
74 // q.User(); // Provide a random number according to the udist distribution
75 // q.User(rvec,n); // Provide n randoms according to the udist distribution
77 // Float_t* x=new Float_t[nbins];
78 // Float_t* y=new Float_t[nbins];
80 // ... code to fill x[] and y[] ..
83 // s.SetUser(x,y,nbins); // Initialise generator for (x[i],y[i]) distribution
84 // s.User(); // Provide a random number according to the user distribution
85 // s.User(rvec,n); // Provide n randoms according to the user distribution
89 // 1) Allowed seed values : 0 <= seed <= 921350143
90 // Default seed = 53310452
91 // 2) To ensure a unique sequence for each run, one can automatically
92 // construct a seed value by e.g. using the date and time.
93 // 3) Using the rvec facility saves a lot of CPU time for large n values.
95 //--- NvE 11-oct-1997 UU-SAP Utrecht
96 ///////////////////////////////////////////////////////////////////////////
103 class AliRandom : public TObject
106 AliRandom(); // Constructor with default sequence
107 AliRandom(Int_t seed); // Constructor with user defined seed
108 AliRandom(Int_t seed,Int_t cnt1,Int_t cnt2); // User defined starting point
109 ~AliRandom(); // Destructor
110 Int_t GetSeed(); // Provide current seed value
111 Int_t GetCnt1(); // Provide current counter value cnt1
112 Int_t GetCnt2(); // Provide current counter value cnt2
113 void Info(); // Print current seed, cnt1 and cnt2
114 Float_t Uniform(); // Uniform dist. within <0,1>
115 Float_t Uniform(Float_t a,Float_t b); // Uniform dist. within <a,b>
116 void Uniform(Float_t* vec,Int_t n); // n uniform randoms in <0,1>
117 void Uniform(Float_t* vec,Int_t n,Float_t a,Float_t b); // see above
118 Float_t Gauss(); // Gaussian dist. with mean=0 sigma=1
119 Float_t Gauss(Float_t mean,Float_t sigma); // Gaussian dist. with mean and sigma
120 void Gauss(Float_t* vec,Int_t n); // n Gaussian randoms mean=0 sigma=1
121 void Gauss(Float_t* vec,Int_t n,Float_t mean,Float_t sigma); // see above
122 Float_t Poisson(Float_t mean); // Poisson dist. with certain mean
123 void Poisson(Float_t* vec,Int_t n,Float_t mean); // n Poisson randoms with mean
124 void SetUser(Float_t a,Float_t b,Int_t n,Float_t (*f)(Float_t)); // User dist. f(x)
125 void SetUser(Float_t* x,Float_t* y,Int_t n); // User dist. arrays
126 Float_t User(); // Provide random in [a,b] according to user distribution
127 void User(Float_t* vec,Int_t n); // n randoms in [a,b] from user dist.
130 Int_t fI,fJ,fSeed,fCnt1,fCnt2,fClip; // Indices, seed and counters
131 Float_t fU[97],fC,fCd,fCm; // The Fibonacci parameters
132 void Start(Int_t seed,Int_t cnt1,Int_t cnt2); // Start at certain point
133 void Unpack(Int_t seed,Int_t& i,Int_t& j,Int_t& k,Int_t& l); // Unpack the seed
134 void Uniform(Int_t n); // n uniform randoms for quick skipping
135 Int_t fNa; //! The number of bins of the area function
136 Float_t* fXa; //! The binned x values of the area function
137 Float_t* fYa; //! The corresponding y values of the area function
138 Float_t fYamin,fYamax; //! The min. and max. y values of the area function
139 Int_t* fIbins; //! The bin numbers of the random x candidates
141 ClassDef(AliRandom,1) // Class definition to enable ROOT I/O