monotone

monotone Mtn Source Tree

Root/randomizer.hh

1#ifndef __RANDOMIZER_HH__
2#define __RANDOMIZER_HH__
3
4// Copyright (C) 2006 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13// This is just a set of utility methods built on top of boost::random.
14//
15// Our purpose is to create a global randomization utility for unit
16// tests. Nothing fancy.
17
18#include <cstddef>
19#include <boost/random/mersenne_twister.hpp>
20
21struct randomizer
22{
23 boost::mt19937 rng;
24
25 // uniform process in [0,n]
26 std::size_t uniform(std::size_t n);
27
28 // boolean process with prob(true) = p, prob(false) = 1-p.
29 bool bernoulli(double p);
30
31 bool flip(std::size_t n = 2);
32};
33
34#endif
35
36
37// Local Variables:
38// mode: C++
39// fill-column: 76
40// c-file-style: "gnu"
41// indent-tabs-mode: nil
42// End:
43// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
44

Archive Download this file

Branches

Tags

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