-
Notifications
You must be signed in to change notification settings - Fork 2
/
RandomNumbers.h
63 lines (54 loc) · 1.58 KB
/
RandomNumbers.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
63
/**
* @file RandomNumbers.h
* @brief Defines the data and methods of the RandomNumbers class
*
* @license This file is distributed under the BSD Open Source License.
* See LICENSE.TXT for details.
**/
#ifndef RANDOMNUMBERS
#define RANDOMNUMBERS
#include <random>
#include "VectorCompatibility.h"
class RandomNumbers {
public:
RandomNumbers();
~RandomNumbers() {}
const double uniformZeroToOne();
const double uniformZeroToTwoPi();
const double gaussian(std::normal_distribution<double> &dist);
private:
std::mt19937_64 engine; //<! Mersenne Twister pseudo-random generator of 64-bit numbers with a state size of 19937 bits
std::uniform_real_distribution<double> zeroToOne;
std::uniform_real_distribution<double> zeroToTwoPi;
};
/**
* @brief Structure to hold precomputed random numbers for use with thermal forces.
**/
struct RandCache {
doubleV r;
double r1, r2
#ifdef __AVX__
r3, r4
#endif
;
RandCache(RandomNumbers &rands) :
#ifdef __AVX__
r(_mm256_set_pd(rands.uniformZeroToOne(),
rands.uniformZeroToOne(),
rands.uniformZeroToOne(),
rands.uniformZeroToOne())),
r1(rands.uniformZeroToTwoPi()), r2(rands.uniformZeroToTwoPi()),
r3(rands.uniformZeroToTwoPi()), r4(rands.uniformZeroToTwoPi()) {}
#else
r(_mm_set_pd(rands.uniformZeroToOne(),
rands.uniformZeroToOne())),
r1(rands.uniformZeroToTwoPi()), r2(rands.uniformZeroToTwoPi()) {}
#endif
RandCache()
: r(set1_pd(0.0)), r1(0.0), r2(0.0)
#ifdef __AVX__
r3(0.0), r4(0.0)
#endif
{}
};
#endif // RANDOMNUMBERS