回答編集履歴
1
msvc
answer
CHANGED
@@ -3,4 +3,50 @@
|
|
3
3
|
- [いつからその方法で偏りのない乱数が得られると錯覚していた? - アスペ日記](https://takeda25.hatenablog.jp/entry/20130818/1376837093)
|
4
4
|
- [Cのrand()よりmt19937の方が速いことがあるという話 - Educational NLP blog](https://edunlp.hatenadiary.com/entry/20130817/1376687595)
|
5
5
|
- [random_shuffle - cpprefjp C++日本語リファレンス](https://cpprefjp.github.io/reference/algorithm/random_shuffle.html)
|
6
|
-
- [uniform_int_distribution - cpprefjp C++日本語リファレンス](https://cpprefjp.github.io/reference/random/uniform_int_distribution.html)
|
6
|
+
- [uniform_int_distribution - cpprefjp C++日本語リファレンス](https://cpprefjp.github.io/reference/random/uniform_int_distribution.html)
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
まあせっかくなので、rand()の性能が悪いことで有名なMSVCでもcateyeさんのコードを実験してみました。
|
11
|
+
|
12
|
+
```cpp
|
13
|
+
#include <iostream>
|
14
|
+
#include <cstdlib>
|
15
|
+
#include <random>
|
16
|
+
//
|
17
|
+
using std::cout;
|
18
|
+
using std::endl;
|
19
|
+
//
|
20
|
+
const int R_MAX = 1000000;
|
21
|
+
|
22
|
+
int main(void)
|
23
|
+
{
|
24
|
+
int rr[4] = { 0 };
|
25
|
+
int mr[4] = { 0 };
|
26
|
+
|
27
|
+
for (int i = 0; i < R_MAX; ++i) {
|
28
|
+
rr[(rand() >> 7) % 3]++;
|
29
|
+
}
|
30
|
+
//
|
31
|
+
std::mt19937 mt(std::random_device{ }());
|
32
|
+
std::uniform_int_distribution<int> dist(0, 2);
|
33
|
+
|
34
|
+
for (int i = 0; i < R_MAX; ++i) {
|
35
|
+
mr[dist(mt)]++;
|
36
|
+
}
|
37
|
+
//
|
38
|
+
for (int i = 0; i < 4; ++i) {
|
39
|
+
cout << i << ": " << rr[i] << " " << mr[i] << endl;
|
40
|
+
}
|
41
|
+
return 0;
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
```
|
46
|
+
0: 335654 333673
|
47
|
+
1: 332437 333180
|
48
|
+
2: 331909 333147
|
49
|
+
3: 0 0
|
50
|
+
```
|
51
|
+
|
52
|
+
まあじゃんけんゲームには影響ないですよね。それはそう。
|