Egglib 2.1.11
C++ library reference manual
Random.hpp
1 /*
2  Copyright 2008,2009,2012 Stéphane De Mita, Mathieu Siol
3  Adapted from MStrat, developed by Charles-Edouard Coste,
4  Thomas M. Bataillon, Mathieu Cotisson, Guy Decoux, Chistophe Rozale,
5  Daniel J. Schoen and Jacques L. David.
6 
7  This file is part of the EggLib library.
8 
9  EggLib is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  EggLib is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with EggLib. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef EGGLIB_RANDOM_HPP
24 #define EGGLIB_RANDOM_HPP
25 
26 namespace egglib {
27 
41  class Random {
42  public:
47  Random();
48 
53  Random(double seed1, double seed2);
54 
61  double erand(double expectation);
62 
68  unsigned int irand(unsigned int max);
69 
75  unsigned int prand(double p);
76 
84  double nrand();
85 
91  unsigned int grand(double);
92 
96  double uniform();
97 
101  double seed1() const;
102 
106  double seed2() const;
107 
111  void seed1(double);
112 
116  void seed2(double);
117 
118  private:
119  // First seed
120  double _seed1;
121 
122  // Second seed
123  double _seed2;
124 
125  /* since the normal random generator draws two numbers at
126  * a time, one is cached and returned at any subsequent call
127  */
128  bool b_ncached;
129  double v_ncached;
130 
131  };
132 }
133 
134 #endif
Pseudo-random number generator.
Definition: Random.hpp:41
unsigned int grand(double)
Draws a number from a geometric law.
Definition: Random.cpp:74
unsigned int irand(unsigned int max)
Draws an integer from a uniform distribution bound by 0 and max (max is not included) ...
Definition: Random.cpp:59
double seed2() const
Gets the current value of the second seed.
Definition: Random.cpp:131
double erand(double expectation)
Draws a number from an exponential distribution.
Definition: Random.cpp:53
double uniform()
Draws a number from a uniform distribution between 0 and 1.
Definition: Random.cpp:80
unsigned int prand(double p)
Draws an integer from a Poisson distribution with parameter p.
Definition: Random.cpp:63
Definition: ABC.cpp:37
Random()
Initializes using default seeds.
Definition: Random.cpp:33
double nrand()
Draws a number from a normal distribution of expectation 0 and variance 1.
Definition: Random.cpp:100
double seed1() const
Gets the current value of the first seed.
Definition: Random.cpp:129

Hosted by 
Get EggLib at SourceForge.net. Fast, secure and Free Open Source software downloads