The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
random_new::rng Class Referenceabstract

this class does not give synced random results derived classes might do. More...

#include <random_new.hpp>

Inheritance diagram for random_new::rng:
Inheritance graph

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

Detailed Description

this class does not give synced random results derived classes might do.

Definition at line 27 of file random_new.hpp.

Constructor & Destructor Documentation

random_new::rng::rng ( )

Definition at line 54 of file random_new.cpp.

random_new::rng::~rng ( )
virtual

Definition at line 60 of file random_new.cpp.

Member Function Documentation

rng & random_new::rng::default_instance ( )
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().

int random_new::rng::get_random_int ( int  min,
int  max 
)
inline

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.

Parameters
minThe minimum value produced.
maxThe 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().

int random_new::rng::get_random_int_in_range_zero_to ( int  max)
private

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.

Parameters
maxThe 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().

virtual uint32_t random_new::rng::next_random_impl ( )
protectedpure virtual

Member Data Documentation

unsigned int random_new::rng::random_calls_
protected

Definition at line 55 of file random_new.hpp.

Referenced by get_random_calls(), and next_random().


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