-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchance.cc
66 lines (40 loc) · 1.61 KB
/
chance.cc
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
61
62
63
64
65
66
// Time-stamp: <2016-03-02 13:49:38 dmendyke>
//
// chance.cc:
//
// Required header files
//-----------------------------------------------------------------------------
#include <chrono> // std::chrono
#include "chance.hh" // chance::number
// NS short hands
//-----------------------------------------------------------------------------
using namespace std; // standard library
using namespace chance; // NS used with this random genrator
// class constructor
//-----------------------------------------------------------------------------
number::number() : generator_( ) {
unsigned int seed = chrono::system_clock::now().time_since_epoch().count();
generator_.seed( seed );
}; // end constructor
// Roll a single die
//-----------------------------------------------------------------------------
int number::generate( int high ) {
static number number_;
uniform_int_distribution<> distribution( 0, high );
return distribution( number_.generator_ );
}; // end generate
// Return a single die roll
//-----------------------------------------------------------------------------
int number::single( int modifier ) {
return number::generate() + 1 + modifier;
}; // end one2six
// Return roll of two dice
//-----------------------------------------------------------------------------
int number::pair( int modifier ) {
return number::single() + number::single( modifier );
}; // end two2twelve
// Return a random number from zero to 'high'
//-----------------------------------------------------------------------------
int number::upto( int high ) {
return number::generate( high );
}; // end upto