-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandomGenerator.h
52 lines (46 loc) · 1.24 KB
/
RandomGenerator.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
#pragma once
#include <cstdlib>
#include<random>
class RandomGenerator {
public:
unsigned seed;
std::mt19937 generator;// using for gen num in range [0,1]
std::uniform_real_distribution<double> distribution;
std::uniform_real_distribution<double> distribution1;
void config(unsigned int sd) {
seed = sd;
generator.seed(seed);
std::uniform_real_distribution<double> valDis(0.0, 1.0);
distribution = valDis;
std::uniform_real_distribution<double> valDis1(0.0, 1.0);
distribution1 = valDis1;
}
//Gen real number in range [0,1]
double genRealInRang01() {
return distribution(generator);
}
//using for mutation_reversal
double genRealInRang01_muta() {
return distribution1(generator);
}
int getIntRand() {
return generator();
}
//gen number in range [u,v]
int getNumInRan(int u, int v) {
return (generator() % (v - u + 1)) + u;
}
/*
inline double randomdN(int n)
{
return (double)rand() / ((double)RAND_MAX / n);
}
inline int randomN(int n)
{
return (rand() % n) + 1;
}
inline int randomR(int u, int v)
{
return (rand() % (v - u + 1)) + u;
}*/
};