回答編集履歴

1

追記

2018/12/15 08:04

投稿

katoy
katoy

スコア22324

test CHANGED
@@ -5,3 +5,75 @@
5
5
  "c" じゃんけん 乱数
6
6
 
7
7
  で google 検索してみましたか?
8
+
9
+
10
+
11
+ 追記
12
+
13
+ ジャンケンではなく、乱数セット方法の質問だったのですね。
14
+
15
+ "c" 乱数 配列 重複 で google 検索してみました。
16
+
17
+
18
+
19
+ - [C言語] ランダムな順列を出力する
20
+
21
+ [http://pcnetbeginners.seesaa.net/article/208460691.html](http://pcnetbeginners.seesaa.net/article/208460691.html)
22
+
23
+
24
+
25
+ これをもとにプログラムを書いてみました。
26
+
27
+ x.c
28
+
29
+ ```
30
+
31
+ #include <stdlib.h>
32
+
33
+ #include <time.h>
34
+
35
+
36
+
37
+ int main(void) {
38
+
39
+ int hand[3];
40
+
41
+ int stock[]={1,2,3}; // この中の数を使う
42
+
43
+ int patterns = 3;
44
+
45
+
46
+
47
+ srand((unsigned)time(NULL));
48
+
49
+ for (int i = 0; i < 3; i++) {
50
+
51
+ // stockの何番目か決める
52
+
53
+ int index = rand() % (patterns - i);
54
+
55
+ hand[i] = stock[index];
56
+
57
+ printf("%d", hand[i]);
58
+
59
+
60
+
61
+ // 使用した値はstockから削除
62
+
63
+ stock[index] = stock[patterns - i - 1];
64
+
65
+ }
66
+
67
+ printf("\n");
68
+
69
+ return 0;
70
+
71
+ }
72
+
73
+ ```
74
+
75
+
76
+
77
+ 実行例
78
+
79
+ ![イメージ説明](1aa4278865f63f9a6e27eff5425ed1f0.png)