#include <mt_rng.hpp>
Public Member Functions | |
mt_rng () | |
mt_rng (const config &cfg) | |
mt_rng (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 | 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... | |
std::mt19937 | mt_ |
State for the random pool (mersenne twister random generator). More... | |
unsigned int | random_calls_ |
Number of time a random number is generated. More... | |
Definition at line 30 of file mt_rng.hpp.
randomness::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.
uint32_t randomness::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(), synced_context::get_rng_for_action(), wesnothd::game::handle_random_choice(), lua_rng::impl_rng_draw(), randomness::rng_deterministic::next_random_impl(), randomness::synced_rng::next_random_impl(), ng::flg_manager::resolve_random(), ng::connect_engine::start_game(), and lg::unique_log_filename().
|
inline |
Definition at line 56 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 54 of file mt_rng.hpp.
References random_seed_.
Referenced by BOOST_AUTO_TEST_CASE().
std::string randomness::mt_rng::get_random_seed_str | ( | ) | const |
Definition at line 100 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 60 of file mt_rng.hpp.
References operator==().
bool randomness::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 randomness::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 randomness::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 89 of file mt_rng.cpp.
Referenced by BOOST_AUTO_TEST_CASE(), lua_rng::impl_rng_seed(), randomness::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 original value is required. |
Definition at line 79 of file mt_rng.cpp.
References DBG_RND, mt_, random_calls_, and random_seed_.
|
private |
State for the random pool (mersenne twister random generator).
Definition at line 68 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 71 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 65 of file mt_rng.hpp.
Referenced by get_next_random(), get_random_seed(), get_random_seed_str(), operator==(), and seed_random().