From 9e54f238fbfced9243cc544c1461f21eefd5b0f1 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 8 Jan 2025 09:56:45 +0100 Subject: add Random.h --- game/Random.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 game/Random.cpp (limited to 'game/Random.cpp') diff --git a/game/Random.cpp b/game/Random.cpp new file mode 100644 index 0000000..59be3c5 --- /dev/null +++ b/game/Random.cpp @@ -0,0 +1,28 @@ +#include + +#include "Random.h" + +float Random::f(float upper, float lower) { + float range = upper - lower; + float x = ((float) rand() / (float) (RAND_MAX)) * range; + return x + lower; +} + +double Random::d(double upper, double lower) { + double range = upper - lower; + double x = ((double) rand() / (double) (RAND_MAX)) * range; + return x + lower; +} + +int Random::i(int upper, int lower) { + int range = upper - lower; + int x = rand() % range; + return x + lower; +} + +unsigned Random::u(unsigned upper, unsigned lower) { + unsigned range = upper - lower; + unsigned x = rand() % range; + return x + lower; +} + -- cgit v1.2.3