this class does not give synced random results derived classes might do. More...
#include <random_new.hpp>
Public Member Functions | |
rng () | |
uint32_t | next_random () |
Provides the next random draw. More... | |
virtual | ~rng () |
unsigned int | get_random_calls () |
Provides the number of random calls to the rng in this context. More... | |
int | get_random_int (int min, int max) |
This helper method provides a random int from the underlying generator, using results of next_random in a manner guaranteed to be cross platform. More... | |
Static Public Member Functions | |
static rng & | default_instance () |
Protected Member Functions | |
virtual uint32_t | next_random_impl ()=0 |
Protected Attributes | |
unsigned int | random_calls_ |
Private Member Functions | |
int | get_random_int_in_range_zero_to (int max) |
Does the hard work of get_random_int. More... | |
this class does not give synced random results derived classes might do.
Definition at line 27 of file random_new.hpp.
random_new::rng::rng | ( | ) |
Definition at line 54 of file random_new.cpp.
|
virtual |
Definition at line 60 of file random_new.cpp.
|
static |
Definition at line 65 of file random_new.cpp.
Referenced by leave_synced_context::leave_synced_context().
unsigned int random_new::rng::get_random_calls | ( | ) |
Provides the number of random calls to the rng in this context.
Note that this may be different from the number of random calls to the underlying rng, and to the random_calls number in save files!
Definition at line 71 of file random_new.cpp.
References random_calls_.
Referenced by synced_context::can_undo().
This helper method provides a random int from the underlying generator,
using results of next_random in a manner guaranteed to be cross platform.
The result will be random in range [min,max] inclusive.
min | The minimum value produced. |
max | The maximum value produced. |
Definition at line 50 of file random_new.hpp.
References get_random_int_in_range_zero_to().
Referenced by generate_gender(), and unit::generate_traits().
Does the hard work of get_random_int.
This code is based on the boost implementation of uniform_smallint.
The result will be random in range [0,max] inclusive.
max | The maximum value produced. |
http://www.boost.org/doc/libs/1_55_0/boost/random/uniform_smallint.hpp Using that code would be ideal, except that boost, and C++11, do not guarantee that it will work the same way on all platforms, or that the results may not be different in future versions of the library. The simplified version I have written should work the same on all platforms, which is the most important thing for us. The existence of "modulo bias" seems less important when we have moved to boost::mt19937, since it guarantees that there are no "bad bits" and has a very large range.
If a standard cross platform version becomes available then this should be replaced.
Definition at line 97 of file random_new.cpp.
References next_random().
Referenced by get_random_int().
uint32_t random_new::rng::next_random | ( | ) |
Provides the next random draw.
This is raw PRG output.
Definition at line 76 of file random_new.cpp.
References next_random_impl(), and random_calls_.
Referenced by context_free_grammar_generator::generate(), get_random_int_in_range_zero_to(), markov_generate_name(), and tod_manager::resolve_random().
|
protectedpure virtual |
Implemented in random_new::synced_rng, and random_new::rng_deterministic.
Referenced by next_random().
|
protected |
Definition at line 55 of file random_new.hpp.
Referenced by get_random_calls(), and next_random().