aboutsummaryrefslogtreecommitdiff
path: root/game/Random.cpp
diff options
context:
space:
mode:
authorMax-001 <maxsmits21@kpnmail.nl>2025-01-08 12:53:10 +0100
committerMax-001 <maxsmits21@kpnmail.nl>2025-01-08 12:53:10 +0100
commit2e65d249e04e1450a4c45a4fb5d48213a75cf3e0 (patch)
tree087433201cc4dd7727cf8aac5f7950b857e8e66f /game/Random.cpp
parentb5ed442444d7243935f7ba58c7d0e0ada743d230 (diff)
parentc9c9702edc58ff8f40b13dc6b86b216421f79e9b (diff)
Merge remote-tracking branch 'origin/master' into max/game2
Diffstat (limited to 'game/Random.cpp')
-rw-r--r--game/Random.cpp28
1 files changed, 28 insertions, 0 deletions
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 <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;
+}
+