-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrand.h
More file actions
63 lines (57 loc) · 1.36 KB
/
rand.h
File metadata and controls
63 lines (57 loc) · 1.36 KB
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
#pragma once
#include <random>
namespace nesting {
namespace rand {
// 随机数引擎
inline std::random_device rd;
inline std::mt19937 random_engine1(rd());
inline std::mt19937 random_engine2(rd());
inline std::mt19937 random_engine3(rd());
inline std::normal_distribution<double> normal_distribution(0, 1);
// 峰值在右,倾向于靠右放置似乎有更强的优化能力
inline std::normal_distribution<double> nd1(0.8, 0.07);
inline std::normal_distribution<double> nd2(0.5, 0.2);
inline std::normal_distribution<double> nd3(0.45, 0.14);
inline std::normal_distribution<double> nd4(0.25, 0.02);
inline std::uniform_real_distribution<> ud1(0.0, 1.0);
inline double random01() {
return ud1(random_engine1);
}
inline double right_nd01() {
auto p = nd1(random_engine1);
if (p < 0) {
p = 0;
} else if (p > 1) {
p = 1;
}
return p;
}
inline double center_nd01() {
auto p = nd2(random_engine2);
if (p < 0) {
p = 0;
} else if (p > 1) {
p = 1;
}
return p;
}
inline double left_nd01() {
auto p = nd3(random_engine2);
if (p < 0) {
p = 0;
} else if (p > 1) {
p = 1;
}
return p;
}
inline double small_sigma_left_nd01() {
auto p = nd4(random_engine3);
if (p < 0) {
p = 0;
} else if (p > 1) {
p = 1;
}
return p;
}
} // namespace rand
} // namespace nesting