1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// die.cpp
//
// Copyright (c) 2009
// Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[die
/*`
For the source of this example see
[@boost://libs/random/example/die.cpp die.cpp].
First we include the headers we need for __mt19937
and __uniform_int_distribution.
*/
/*`
We use __mt19937 with the default seed as a source of
randomness. The numbers produced will be the same
every time the program is run. One common method to
change this is to seed with the current time (`std::time(0)`
defined in ctime).
*/
boost::random::mt19937 gen;
/*`
[note We are using a /global/ generator object here. This
is important because we don't want to create a new [prng
pseudo-random number generator] at every call]
*/
/*`
Now we can define a function that simulates an ordinary
six-sided die.
*/
int
//]
int