#include <mt_rng.hpp>
Public Member Functions | |
mt_rng () | |
mt_rng (const config &cfg) | |
mt_rng (boost::uint32_t seed) | |
uint32_t | get_next_random () |
Get a new random number. More... | |
void | seed_random (const std::string &seed, const unsigned int call_count=0) |
Same as uint32_t version, but uses a stringstream to convert given hex string. More... | |
void | rotate_random () |
Resets the random to the 0 calls and the seed to the random this way we stay in the same sequence but don't have a lot calls. More... | |
uint32_t | get_random_seed () const |
std::string | get_random_seed_str () const |
unsigned int | get_random_calls () const |
bool | operator== (const mt_rng &other) const |
bool | operator!= (const mt_rng &other) const |
Private Member Functions | |
void | discard (const unsigned int call_count) |
On my local version of boost::random, I can use mt_.discard to discard a number of rng results. More... | |
void | seed_random (const uint32_t seed, const unsigned int call_count=0) |
Seeds the random pool. More... | |
Private Attributes | |
uint32_t | random_seed_ |
Initial seed for the pool. More... | |
boost::mt19937 | mt_ |
State for the random pool (boost mersenne twister random generator). More... | |
unsigned int | random_calls_ |
Number of time a random number is generated. More... | |
Definition at line 33 of file mt_rng.hpp.
rand_rng::mt_rng::mt_rng | ( | ) |
Definition at line 32 of file mt_rng.cpp.
|
explicit |
Definition at line 48 of file mt_rng.cpp.
References seed_random(), and config::attribute_value::str().
|
explicit |
Definition at line 40 of file mt_rng.cpp.
On my local version of boost::random, I can use mt_.discard to discard a number of rng results.
In older versions this seems to be unavailable. I'm implementing as a private method of mt_rng, following description here: http://www.boost.org/doc/libs/1_51_0/doc/html/boost/random/mersenne_twister_engine.html#id1408119-bb
Definition at line 108 of file mt_rng.cpp.
References get_next_random(), and i.
Referenced by seed_random().
uint32_t rand_rng::mt_rng::get_next_random | ( | ) |
Get a new random number.
Definition at line 63 of file mt_rng.cpp.
References DBG_RND, mt_, random_calls_, and random_seed_.
Referenced by BOOST_AUTO_TEST_CASE(), discard(), wesnothd::game::handle_random_choice(), lua_rng::impl_rng_draw(), random_new::rng_deterministic::next_random_impl(), random_new::synced_rng::next_random_impl(), ng::flg_manager::resolve_random(), and ng::connect_engine::start_game().
|
inline |
Definition at line 59 of file mt_rng.hpp.
References random_calls_.
Referenced by BOOST_AUTO_TEST_CASE(), carryover_info::to_config(), carryover_info::transfer_to(), and game_data::write_snapshot().
|
inline |
Definition at line 57 of file mt_rng.hpp.
References random_seed_.
Referenced by BOOST_AUTO_TEST_CASE().
std::string rand_rng::mt_rng::get_random_seed_str | ( | ) | const |
Definition at line 99 of file mt_rng.cpp.
References random_seed_.
Referenced by BOOST_AUTO_TEST_CASE(), carryover_info::to_config(), carryover_info::transfer_to(), and game_data::write_snapshot().
|
inline |
Definition at line 63 of file mt_rng.hpp.
References operator==().
bool rand_rng::mt_rng::operator== | ( | const mt_rng & | other | ) | const |
Definition at line 57 of file mt_rng.cpp.
References mt_, random_calls_, and random_seed_.
Referenced by operator!=().
void rand_rng::mt_rng::rotate_random | ( | ) |
Resets the random to the 0 calls and the seed to the random this way we stay in the same sequence but don't have a lot calls.
Used when moving to the next scenario.
Definition at line 74 of file mt_rng.cpp.
References mt_, and seed_random().
Referenced by saved_game::convert_to_start_save().
void rand_rng::mt_rng::seed_random | ( | const std::string & | seed, |
const unsigned int | call_count = 0 |
||
) |
Same as uint32_t version, but uses a stringstream to convert given hex string.
seed | A hex string. Should not have 0x leading. |
call_count | Value to set internal call counter to after seeding. |
Definition at line 88 of file mt_rng.cpp.
References DBG_RND.
Referenced by BOOST_AUTO_TEST_CASE(), lua_rng::impl_rng_seed(), random_new::synced_rng::initialize(), mt_rng(), and rotate_random().
|
private |
Seeds the random pool.
This is the old version, I would like to mark this private.
seed | The initial value for the random engine. |
call_count | Upon loading we need to restore the state at saving so set the number of times a random number is generated for replays the orginal value is required. |
Definition at line 79 of file mt_rng.cpp.
References DBG_RND, discard(), mt_, random_calls_, and random_seed_.
|
private |
State for the random pool (boost mersenne twister random generator).
Definition at line 71 of file mt_rng.hpp.
Referenced by get_next_random(), operator==(), rotate_random(), and seed_random().
|
private |
Number of time a random number is generated.
Definition at line 74 of file mt_rng.hpp.
Referenced by get_next_random(), get_random_calls(), operator==(), and seed_random().
|
private |
Initial seed for the pool.
Definition at line 68 of file mt_rng.hpp.
Referenced by get_next_random(), get_random_seed(), get_random_seed_str(), operator==(), and seed_random().