7 #include <lazarus/common.h>
41 static void seed(
unsigned seed);
54 template <
typename T,
typename U,
55 typename std::enable_if_t<
56 (std::is_integral<T>::value || std::is_unsigned<T>::value)
57 && (std::is_integral<U>::value || std::is_unsigned<U>::value)
59 static typename std::common_type<T, U>::type
range(T a, U b)
61 typedef typename std::common_type<T, U>::type common_type;
62 auto _a =
static_cast<common_type
>(a);
63 auto _b =
static_cast<common_type
>(b);
66 return std::uniform_int_distribution<common_type>(_a, _b)(generator);
81 template <
typename T,
typename U,
82 typename std::enable_if_t<
83 std::is_floating_point<T>::value || std::is_floating_point<U>::value
85 static typename std::common_type<T, U>::type
range(T a, U b)
87 typedef typename std::common_type<T, U>::type common_type;
88 auto _a =
static_cast<common_type
>(a);
89 auto _b =
static_cast<common_type
>(b);
92 return std::uniform_real_distribution<common_type>(_a, _b)(generator);
99 static ulong
roll(
unsigned sides=6,
unsigned times=1);
104 static bool oneIn(
unsigned n);
115 static double normal(
double mean,
double stdev);
124 template <
typename C,
typename T =
typename C::value_type>
125 static T&
choice(C& container);
128 static std::mt19937 generator;
131 template <
typename C,
typename T>
135 size_t size = container.size();
140 return container[idx];
static ulong roll(unsigned sides=6, unsigned times=1)
Rolls a dice with the specified number of sides a certain number of times and returns the total resul...
Definition: Random.cpp:32
static void seed()
Sets a new seed for the random generator using a hardware random device if available, or a seed using the current time.
Definition: Random.cpp:11
static T & choice(C &container)
Return a reference to a random item from a container.
Definition: Random.h:132
static std::common_type< T, U >::type range(T a, U b)
Return a random integral between the two given numbers with equal probability.
Definition: Random.h:59
The Random class provides a simple interface for commonly used RNG functionality. ...
Definition: Random.h:25
static double normal(double mean, double stdev)
Return a random number generated from a normal distribution.
Definition: Random.cpp:52
static bool oneIn(unsigned n)
Return true with a 1 in n probability.
Definition: Random.cpp:45