回答編集履歴
1
msvc
test
CHANGED
@@ -9,3 +9,95 @@
|
|
9
9
|
- [random_shuffle - cpprefjp C++日本語リファレンス](https://cpprefjp.github.io/reference/algorithm/random_shuffle.html)
|
10
10
|
|
11
11
|
- [uniform_int_distribution - cpprefjp C++日本語リファレンス](https://cpprefjp.github.io/reference/random/uniform_int_distribution.html)
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
まあせっかくなので、rand()の性能が悪いことで有名なMSVCでもcateyeさんのコードを実験してみました。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```cpp
|
24
|
+
|
25
|
+
#include <iostream>
|
26
|
+
|
27
|
+
#include <cstdlib>
|
28
|
+
|
29
|
+
#include <random>
|
30
|
+
|
31
|
+
//
|
32
|
+
|
33
|
+
using std::cout;
|
34
|
+
|
35
|
+
using std::endl;
|
36
|
+
|
37
|
+
//
|
38
|
+
|
39
|
+
const int R_MAX = 1000000;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
int main(void)
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
int rr[4] = { 0 };
|
48
|
+
|
49
|
+
int mr[4] = { 0 };
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
for (int i = 0; i < R_MAX; ++i) {
|
54
|
+
|
55
|
+
rr[(rand() >> 7) % 3]++;
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
//
|
60
|
+
|
61
|
+
std::mt19937 mt(std::random_device{ }());
|
62
|
+
|
63
|
+
std::uniform_int_distribution<int> dist(0, 2);
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
for (int i = 0; i < R_MAX; ++i) {
|
68
|
+
|
69
|
+
mr[dist(mt)]++;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
//
|
74
|
+
|
75
|
+
for (int i = 0; i < 4; ++i) {
|
76
|
+
|
77
|
+
cout << i << ": " << rr[i] << " " << mr[i] << endl;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
return 0;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
0: 335654 333673
|
92
|
+
|
93
|
+
1: 332437 333180
|
94
|
+
|
95
|
+
2: 331909 333147
|
96
|
+
|
97
|
+
3: 0 0
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
まあじゃんけんゲームには影響ないですよね。それはそう。
|