The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
rand_rng::mt_rng Class Reference

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

Detailed Description

Definition at line 33 of file mt_rng.hpp.

Constructor & Destructor Documentation

rand_rng::mt_rng::mt_rng ( )

Definition at line 32 of file mt_rng.cpp.

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

Definition at line 48 of file mt_rng.cpp.

References seed_random(), and config::attribute_value::str().

rand_rng::mt_rng::mt_rng ( boost::uint32_t  seed)
explicit

Definition at line 40 of file mt_rng.cpp.

Member Function Documentation

void rand_rng::mt_rng::discard ( const unsigned int  call_count)
private

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 ( )
unsigned int rand_rng::mt_rng::get_random_calls ( ) const
inline
uint32_t rand_rng::mt_rng::get_random_seed ( ) const
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
bool rand_rng::mt_rng::operator!= ( const mt_rng other) const
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.

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.

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

void rand_rng::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 orginal value is required.

Definition at line 79 of file mt_rng.cpp.

References DBG_RND, discard(), mt_, random_calls_, and random_seed_.

Member Data Documentation

boost::mt19937 rand_rng::mt_rng::mt_
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().

unsigned int rand_rng::mt_rng::random_calls_
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().

uint32_t rand_rng::mt_rng::random_seed_
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().


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