spot  1.2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
random.hh
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2013 Laboratoire de Recherche et Développement
3 // de l'Epita (LRDE).
4 // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
5 // département Systèmes Répartis Coopératifs (SRC), Université Pierre
6 // et Marie Curie.
7 //
8 // This file is part of Spot, a model checking library.
9 //
10 // Spot is free software; you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Spot is distributed in the hope that it will be useful, but WITHOUT
16 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 // License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef SPOT_MISC_RANDOM_HH
24 # define SPOT_MISC_RANDOM_HH
25 
26 # include "common.hh"
27 # include <cmath>
28 
29 namespace spot
30 {
34 
38  SPOT_API void srand(unsigned int seed);
39 
44  SPOT_API int rrand(int min, int max);
45 
50  SPOT_API int mrand(int max);
51 
56  SPOT_API double drand();
57 
64  SPOT_API double nrand();
65 
71  SPOT_API double bmrand();
72 
84  template<double (*gen)()>
85  class barand
86  {
87  public:
88  barand(int n, double p)
89  : n_(n), m_(n * p), s_(sqrt(n * p * (1 - p)))
90  {
91  }
92 
93  int
94  rand() const
95  {
96  int res;
97 
98  for (;;)
99  {
100  double x = gen() * s_ + m_;
101  if (x < 0.0)
102  continue;
103  res = static_cast<int> (x);
104  if (res <= n_)
105  break;
106  }
107  return res;
108  }
109  protected:
110  const int n_;
111  const double m_;
112  const double s_;
113  };
114 
119  SPOT_API int prand(double p);
121 }
122 
123 #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 Thu May 15 2014 11:04:11 for spot by doxygen 1.8.4