diff options
Diffstat (limited to 'src/z-rand.hpp')
-rw-r--r-- | src/z-rand.hpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/src/z-rand.hpp b/src/z-rand.hpp index f2e3ce5c..b04523c3 100644 --- a/src/z-rand.hpp +++ b/src/z-rand.hpp @@ -1,8 +1,9 @@ #pragma once #include "h-basic.h" +#include "seed_fwd.hpp" - +#include <string> /**** Available constants ****/ @@ -19,17 +20,34 @@ /**** Available Variables ****/ -extern bool_ Rand_quick; -extern u32b Rand_value; -extern u16b Rand_place; -extern u32b Rand_state[RAND_DEG]; +/** + * Change to "quick" RNG, using the given seed. + */ +void set_quick_rng(seed_t const &seed); + + +/** + * Change to "complex" RNG which uses the "non-deterministic" seed. + */ +void set_complex_rng(); + + +/** + * Get a copy of the state of the "complex" RNG. + */ +std::string get_complex_rng_state(); + +/** + * Set the state of the "complex" RNG. The given array must have + * been previously obtained via the get_complex_rng_state() function. + */ +void set_complex_rng_state(std::string const &state); /**** Available Functions ****/ -void Rand_state_init(u32b seed); -s32b Rand_mod(s32b m); +void Rand_state_init(); s16b randnor(int mean, int stand); s32b damroll(s16b num, s16b sides); s32b maxroll(s16b num, s16b sides); @@ -40,7 +58,7 @@ s32b maxroll(s16b num, s16b sides); bool magik(s32b p); /* - * Generates a random long integer X where O<=X<M. + * Generates a random long integer X where 0<=X<M. * The integer X falls along a uniform distribution. * For example, if M is 100, you get "percentile dice" */ @@ -65,3 +83,23 @@ s32b rand_range(s32b a, s32b b); * Note: rand_spread(A,D) == rand_range(A-D,A+D) */ s32b rand_spread(s32b a, s32b d); + +/** + * Choose a random element in from the given container. + * The container, C, must fulfill the Container concept + * whose iterators fulfill the RandomIterator concept. + **/ +template <class C> typename C::const_iterator uniform_element(C const &c) +{ + return c.cbegin() + rand_int(c.size()); +} + +/** + * Choose a random element in from the given container. + * The container, C, must fulfill the Container concept + * whose iterators fulfill the RandomIterator concept. + **/ +template <class C> typename C::iterator uniform_element(C &c) +{ + return c.begin() + rand_int(c.size()); +} |