回答編集履歴

1

整理

2018/09/27 07:37

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -4,15 +4,17 @@
4
4
 
5
5
 
6
6
 
7
- srandを呼び出さずにrandを用いた場合、srand(1)の乱数列を用いるそうです。
7
+ srandを呼び出さずにrandを用いた場合、srand(1) の乱数列を用いるそうです。
8
8
 
9
- 実際にsrand(1)を呼び出した結果と比較してみると良いでしょう。
9
+ 実際に srand(1) を呼び出した結果と比較してみると良いでしょう。
10
10
 
11
11
  > **void srand( unsigned seed );**
12
12
 
13
13
  Seeds the pseudo-random number generator used by std::rand() with the value seed.
14
14
 
15
15
  If rand() is used before any calls to srand(), rand() behaves as if it was seeded with srand(1).
16
+
17
+ Each time rand() is seeded with the same seed, it must produce the same sequence of values.
16
18
 
17
19
 
18
20
 
@@ -22,4 +24,68 @@
22
24
 
23
25
  srandの有無を超えて、シード値を毎回変えているかどうかの方が重要です。
24
26
 
25
- srand引数に時刻を与えているのは、実行ごとに別の値を使うための工夫でしかありません。
27
+ シード値として時刻を与えているのは、実行ごとに別の値を使うための工夫でしかありません。
28
+
29
+
30
+
31
+ 実験
32
+
33
+ ---
34
+
35
+ **srandを呼び出さない場合** [Wandbox](https://wandbox.org/permlink/EU4z00CMWerb22Jh)
36
+
37
+ ```
38
+
39
+ 1804289383
40
+
41
+ 846930886
42
+
43
+ 1681692777
44
+
45
+ 1714636915
46
+
47
+ 1957747793
48
+
49
+ 424238335
50
+
51
+ 719885386
52
+
53
+ 1649760492
54
+
55
+ 596516649
56
+
57
+ 1189641421
58
+
59
+ ```
60
+
61
+
62
+
63
+ **srand(1)を与えた場合** [Wandbox](https://wandbox.org/permlink/EhhPV4zAt4TLhDcr)
64
+
65
+ ```
66
+
67
+ 1804289383
68
+
69
+ 846930886
70
+
71
+ 1681692777
72
+
73
+ 1714636915
74
+
75
+ 1957747793
76
+
77
+ 424238335
78
+
79
+ 719885386
80
+
81
+ 1649760492
82
+
83
+ 596516649
84
+
85
+ 1189641421
86
+
87
+ ```
88
+
89
+
90
+
91
+ 実際に同じ結果になることが確認できます。