回答編集履歴

1

追記

2018/02/20 07:29

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -1 +1,57 @@
1
1
  int Array[32768] の中からデタラメにひとつ取り出すため、何番目を取り出せばいいかを表すデタラメな15bit-int(0~32767)を作るには? って訊いてる?
2
+
3
+
4
+
5
+ [追記] srand/rand なんか使わない。
6
+
7
+
8
+
9
+ ```C++
10
+
11
+ #include <iostream>
12
+
13
+ #include <random>
14
+
15
+ #include <functional>
16
+
17
+
18
+
19
+ int main() {
20
+
21
+ using namespace std;
22
+
23
+
24
+
25
+ // 範囲0~32767の一様乱数
26
+
27
+ // メルセンヌ・ツイスターの'種'は省略。好きに埋めておくれ。
28
+
29
+ auto rand = bind(uniform_int_distribution<int>(0, 32767), mt19937());
30
+
31
+
32
+
33
+ const int N = 35;
34
+
35
+ int Array[N];
36
+
37
+
38
+
39
+ // randを使って埋める
40
+
41
+ generate_n(Array, N, rand);
42
+
43
+
44
+
45
+ // デキタカナ?
46
+
47
+ for ( int item : Array ) {
48
+
49
+ cout << item << ' ';
50
+
51
+ }
52
+
53
+ cout << endl;
54
+
55
+ }
56
+
57
+ ```