monotone

monotone Mtn Source Tree

Root/randomizer.cc

1// Copyright (C) 2006 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#include "randomizer.hh"
11
12bool randomizer::flip(size_t n)
13{
14 return bernoulli(1.0 / static_cast<double>(n));
15}
16
17size_t randomizer::uniform(size_t n)
18{
19 return boost::random_number_generator<boost::mt19937>(rng)(n);
20}
21
22bool randomizer::bernoulli(double p)
23{
24 typedef boost::mt19937& rng_t;
25 typedef boost::bernoulli_distribution<double> dist_t;
26 return boost::variate_generator<rng_t, dist_t>(rng, dist_t(p))();
27}
28
29// Local Variables:
30// mode: C++
31// fill-column: 76
32// c-file-style: "gnu"
33// indent-tabs-mode: nil
34// End:
35// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status