spot  1.1.3
random.hh
Go to the documentation of this file.
1 // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
2 // département Systèmes Répartis Coopératifs (SRC), Université Pierre
3 // et Marie Curie.
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #ifndef SPOT_MISC_RANDOM_HH
21 # define SPOT_MISC_RANDOM_HH
22 
23 # include <cmath>
24 
25 namespace spot
26 {
30 
34  void srand(unsigned int seed);
35 
40  int rrand(int min, int max);
41 
46  int mrand(int max);
47 
52  double drand();
53 
60  double nrand();
61 
67  double bmrand();
68 
80  template<double (*gen)()>
81  class barand
82  {
83  public:
84  barand(int n, double p)
85  : n_(n), m_(n * p), s_(sqrt(n * p * (1 - p)))
86  {
87  }
88 
89  int
90  rand() const
91  {
92  int res;
93 
94  for (;;)
95  {
96  double x = gen() * s_ + m_;
97  if (x < 0.0)
98  continue;
99  res = static_cast<int> (x);
100  if (res <= n_)
101  break;
102  }
103  return res;
104  }
105  protected:
106  const int n_;
107  const double m_;
108  const double s_;
109  };
110 
115  int prand(double p);
117 }
118 
119 #endif // SPOT_MISC_RANDOM_HH

Please direct any question, comment, or bug report to the Spot mailing list at spot@lrde.epita.fr.
Generated on Tue Jul 9 2013 14:04:33 for spot by doxygen 1.8.4