ge211
ge211_random.cpp
1 #include "ge211_random.h"
2 
3 #include <chrono>
4 
5 using namespace std;
6 
7 namespace ge211 {
8 
9 static auto construct_engine()
10 {
11  random_device rd;
12  auto time = static_cast<random_device::result_type>(
13  chrono::high_resolution_clock()
14  .now().time_since_epoch().count());
15  return mt19937_64(rd() ^ time);
16 }
17 
18 Random::Random()
19  : generator_{construct_engine()}
20 { }
21 
22 bool Random::random_bool(double ptrue)
23 {
24  return up_to(1.0) < ptrue;
25 }
26 
27 }
The game engine namespace.
Definition: ge211.h:17
bool random_bool(double ptrue=0.5)
Returns a random bool that is true with probability ptrue.