-
Notifications
You must be signed in to change notification settings - Fork 0
/
RandomNumberGenerator.h
63 lines (52 loc) · 2.03 KB
/
RandomNumberGenerator.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* File: RandomNumberGenerator.h
* Author: RM
*
* Created on 31. Juli 2013, 15:03
*/
#ifndef RANDOMNUMBERGENERATOR_H
#define RANDOMNUMBERGENERATOR_H
#include <random>
#include <vector>
#include <iostream>
#include "Definitions.h"
typedef mt19937 MTRNG;
/**
* Adapted from http://stackoverflow.com/questions/7114043/random-number-generation-in-c11-how-to-generate-how-do-they-work.
* and http://stackoverflow.com/questions/14009637/c11-random-numbers.
* Uses <random> from C++11 to create uniform distributions.<br>
* Currently configured for production of uniformly distributed random float values
* between 0 and 1.<br>
* Uses the Mersenne Twister with a popular choice of parameters as RNG.
*/
class RandomNumberGenerator
{
public:
RandomNumberGenerator(long long seed = mt19937::default_seed);
RandomNumberGenerator(const RandomNumberGenerator& orig);
virtual ~RandomNumberGenerator();
/**
* Returns next random float from random number generator.
* @return
*/
float rand();
/**
* Generates container.capacity() random numbers.
* @param container
*/
void generateRandomNumbers(vector<float>& container);
private:
// Range limits for distribution
static const uint DISTRIBUTION_MIN = 0;
static const uint DISTRIBUTION_MAX = 1;
// Seed
uint seed;
// Random number generator
MTRNG generator;
// Uniform distribution for float values between DISTRIBUTION_MIN and DISTRIBUTION_MAX
uniform_real_distribution<float> uniformFloatDistribution { uniform_real_distribution<float>(
RandomNumberGenerator::DISTRIBUTION_MIN,
RandomNumberGenerator::DISTRIBUTION_MAX)
};
} ;
#endif /* RANDOMNUMBERGENERATOR_H */