summaryrefslogtreecommitdiff
path: root/src/utils/RandomGenerator.cpp
blob: 9ffe4fb24d75b413c42a4a4cff0ea886dc8ba34b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}