Class supporting random number generation using /dev/urandom Example usage. More...
#include <random.h>
Static Public Member Functions | |
static unsigned long | rand () throw (std::runtime_error) |
Produces a random unsigned long taken from /dev/urandom. | |
static bool | gamble (size_t chances, size_t out_of) throw (std::runtime_error) |
Gamble such that the chance of 'true' is N out of M. | |
static size_t | pick_one (size_t min, size_t max) throw (std::runtime_error) |
Pick a number out of a range. |
Class supporting random number generation using /dev/urandom Example usage.
unsigned long key = Dv::Util::Random::rand();
Definition at line 15 of file random.h.
static unsigned long Dv::Util::Random::rand | ( | ) | throw (std::runtime_error) [static] |
Produces a random unsigned long taken from /dev/urandom.
An exception is thrown if anything goes wrong, e.g. the file /dev/urandom cannot be opened.
Should probably automatically switch to another implementation if /dev/urandom is not available. This is probably a naive approach but will do for the simple purposes it is used for.
Referenced by gamble().
static bool Dv::Util::Random::gamble | ( | size_t | chances, | |
size_t | out_of | |||
) | throw (std::runtime_error) [inline, static] |
static size_t Dv::Util::Random::pick_one | ( | size_t | min, | |
size_t | max | |||
) | throw (std::runtime_error) [static] |
Pick a number out of a range.
min | of range [min..max[ | |
max | of range [min..max[ |
if | min > max |
dvutil-1.0.10 | [ 5 December, 2009] |