summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/IRandomGenerator.h17
-rw-r--r--src/utils/RandomGenerator.cpp38
-rw-r--r--src/utils/RandomGenerator.h16
-rw-r--r--src/utils/TimeProvider.cpp6
-rw-r--r--src/utils/TimeProvider.h12
5 files changed, 89 insertions, 0 deletions
diff --git a/src/utils/IRandomGenerator.h b/src/utils/IRandomGenerator.h
new file mode 100644
index 0000000..08c6f95
--- /dev/null
+++ b/src/utils/IRandomGenerator.h
@@ -0,0 +1,17 @@
+#ifndef I_RANDOM_GENERATOR_H
+#define I_RANDOM_GENERATOR_H
+
+#include <QtCore>
+
+class IRandomGenerator
+{
+public:
+ virtual ~IRandomGenerator() {}
+ virtual double getInRange_11() const = 0;
+ virtual double getInRange_01() const = 0;
+ virtual int getRand() const = 0;
+ virtual int getRand(int maxNum) const = 0;
+ virtual QByteArray getArray() const = 0;
+};
+
+#endif
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;
+}
diff --git a/src/utils/RandomGenerator.h b/src/utils/RandomGenerator.h
new file mode 100644
index 0000000..da36070
--- /dev/null
+++ b/src/utils/RandomGenerator.h
@@ -0,0 +1,16 @@
+#ifndef RANDOM_GENERATOR_H
+#define RANDOM_GENERATOR_H
+
+#include "IRandomGenerator.h"
+
+class RandomGenerator: public IRandomGenerator
+{
+public:
+ RandomGenerator();
+ double getInRange_11() const;
+ double getInRange_01() const;
+ int getRand() const;
+ int getRand(int maxNum) const;
+ QByteArray getArray() const;
+};
+#endif
diff --git a/src/utils/TimeProvider.cpp b/src/utils/TimeProvider.cpp
new file mode 100644
index 0000000..db24c5e
--- /dev/null
+++ b/src/utils/TimeProvider.cpp
@@ -0,0 +1,6 @@
+#include "TimeProvider.h"
+
+QDateTime TimeProvider::get()
+{
+ return QDateTime::currentDateTime();
+}
diff --git a/src/utils/TimeProvider.h b/src/utils/TimeProvider.h
new file mode 100644
index 0000000..697d8eb
--- /dev/null
+++ b/src/utils/TimeProvider.h
@@ -0,0 +1,12 @@
+#ifndef TIME_PROVIDER_H
+#define TIME_PROVIDER_H
+
+#include <QtCore>
+
+class TimeProvider
+{
+public:
+ static QDateTime get();
+};
+
+#endif