diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 21:30:38 +0100 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 21:30:38 +0100 | 
| commit | a04cb74fee079e3ee43ae5fae32fc2674409822c (patch) | |
| tree | 403e681a768ee68b54569e93d98e741878cd7975 /backend/RNG.cpp | |
| parent | 9283e1eb66d6ff96b02f317e28cb6ff060953cdf (diff) | |
implement movement
Diffstat (limited to 'backend/RNG.cpp')
| -rw-r--r-- | backend/RNG.cpp | 32 | 
1 files changed, 32 insertions, 0 deletions
diff --git a/backend/RNG.cpp b/backend/RNG.cpp new file mode 100644 index 0000000..bc3e57b --- /dev/null +++ b/backend/RNG.cpp @@ -0,0 +1,32 @@ +#include "RNG.h" + +using std::uniform_int_distribution; +using std::uniform_real_distribution; + +RNG::RNG() : dev(), rng(dev()) { } + +RNG & RNG::get() { +	static RNG instance; +	return instance; +} + +int RNG::rand_int(const int upper) { +	return this->rand_int(0, upper); +} +int RNG::rand_int(const int lower, const int upper) { +	uniform_int_distribution<int> random_dist(lower, upper); +	return random_dist(rng); +} + +double RNG::rand_double() { +	return this->rand_double(0.f, 1.f); +} +double RNG::rand_double(const double lower, const double upper) { +	uniform_real_distribution<double> random_dist(lower, upper); +	return random_dist(rng); +} + +bool RNG::rand_bool() { +	return rand_int(0, 1); +} +  |