summaryrefslogtreecommitdiff
path: root/src/utils/RandomGenerator.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/utils/RandomGenerator.cpp
Initial mirror commitHEADmaster
Diffstat (limited to 'src/utils/RandomGenerator.cpp')
-rw-r--r--src/utils/RandomGenerator.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/utils/RandomGenerator.cpp b/src/utils/RandomGenerator.cpp
new file mode 100644
index 0000000..9ffe4fb
--- /dev/null
+++ b/src/utils/RandomGenerator.cpp
@@ -0,0 +1,38 @@
+#include "RandomGenerator.h"
+
+#include <stdlib.h>
+#include <time.h>
+
+RandomGenerator::RandomGenerator()
+{
+ srand(time(NULL));
+}
+
+double RandomGenerator::getInRange_11() const
+{
+ return 2. * rand() / RAND_MAX - 1;
+}
+
+double RandomGenerator::getInRange_01() const
+{
+ return float(rand()) / RAND_MAX;
+}
+
+int RandomGenerator::getRand() const
+{
+ return rand();
+}
+
+int RandomGenerator::getRand(int maxNum) const
+{
+ return rand() % maxNum;
+}
+
+QByteArray RandomGenerator::getArray() const
+{
+ const int size = 16;
+ QByteArray res;
+ for(int i = 0; i < size; i++)
+ res += rand() % 256;
+ return res;
+}