aboutsummaryrefslogtreecommitdiff
path: root/game/Random.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2025-01-11 21:32:30 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2025-01-11 21:32:30 +0100
commita6803980f1e74ecf1abb007b7c77f00d2cd92c43 (patch)
tree425ca961b27117d6e5d5fa0ae5cfca93351e0b33 /game/Random.cpp
parent6bc0025e4c24ed6659d993f3469c10615fb0e273 (diff)
parent525636bb2158ecea68ebb9d6b8d2dc722524c5e5 (diff)
merge master into loek/doxygen
Diffstat (limited to 'game/Random.cpp')
-rw-r--r--game/Random.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/game/Random.cpp b/game/Random.cpp
new file mode 100644
index 0000000..64cf1f3
--- /dev/null
+++ b/game/Random.cpp
@@ -0,0 +1,29 @@
+#include <cstdlib>
+
+#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;
+}
+
+bool Random::b() { return rand() % 2; }