The Battle for Wesnoth  1.15.0+dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
randomness::mt_rng Class Reference

#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...
 

Detailed Description

Definition at line 29 of file mt_rng.hpp.

Constructor & Destructor Documentation

◆ mt_rng() [1/3]

randomness::mt_rng::mt_rng ( )

Definition at line 31 of file mt_rng.cpp.

◆ mt_rng() [2/3]

randomness::mt_rng::mt_rng ( const config cfg)
explicit

Definition at line 47 of file mt_rng.cpp.

References seed_random(), and config_attribute_value::str().

◆ mt_rng() [3/3]

randomness::mt_rng::mt_rng ( uint32_t  seed)
explicit

Definition at line 39 of file mt_rng.cpp.

Member Function Documentation

◆ get_next_random()

uint32_t randomness::mt_rng::get_next_random ( )

◆ get_random_calls()

unsigned int randomness::mt_rng::get_random_calls ( ) const
inline

◆ get_random_seed()

uint32_t randomness::mt_rng::get_random_seed ( ) const
inline

Definition at line 53 of file mt_rng.hpp.

References get_random_seed_str(), and random_seed_.

Referenced by BOOST_AUTO_TEST_CASE().

◆ get_random_seed_str()

std::string randomness::mt_rng::get_random_seed_str ( ) const

◆ operator!=()

bool randomness::mt_rng::operator!= ( const mt_rng other) const
inline

Definition at line 59 of file mt_rng.hpp.

References operator==().

◆ operator==()

bool randomness::mt_rng::operator== ( const mt_rng other) const

Definition at line 56 of file mt_rng.cpp.

References mt_, random_calls_, and random_seed_.

Referenced by get_random_calls(), and operator!=().

◆ rotate_random()

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 73 of file mt_rng.cpp.

References mt_, and seed_random().

Referenced by saved_game::convert_to_start_save().

◆ seed_random() [1/2]

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.

Parameters
seedA hex string. Should not have 0x leading.
call_countValue to set internal call counter to after seeding.

Definition at line 88 of file mt_rng.cpp.

References DBG_RND, and s.

Referenced by BOOST_AUTO_TEST_CASE(), lua_rng::impl_rng_seed(), randomness::synced_rng::initialize(), mt_rng(), and rotate_random().

◆ seed_random() [2/2]

void randomness::mt_rng::seed_random ( const uint32_t  seed,
const unsigned int  call_count = 0 
)
private

Seeds the random pool.

This is the old version, I would like to mark this private.

Parameters
seedThe initial value for the random engine.
call_countUpon 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 78 of file mt_rng.cpp.

References DBG_RND, mt_, random_calls_, and random_seed_.

Member Data Documentation

◆ mt_

std::mt19937 randomness::mt_rng::mt_
private

State for the random pool (mersenne twister random generator).

Definition at line 67 of file mt_rng.hpp.

Referenced by get_next_random(), operator==(), rotate_random(), and seed_random().

◆ random_calls_

unsigned int randomness::mt_rng::random_calls_
private

Number of time a random number is generated.

Definition at line 70 of file mt_rng.hpp.

Referenced by get_next_random(), get_random_calls(), operator==(), and seed_random().

◆ random_seed_

uint32_t randomness::mt_rng::random_seed_
private

Initial seed for the pool.

Definition at line 64 of file mt_rng.hpp.

Referenced by get_next_random(), get_random_seed(), get_random_seed_str(), operator==(), and seed_random().


The documentation for this class was generated from the following files: