回答編集履歴

1

ついき

2015/06/12 10:17

投稿

Tak1wa
Tak1wa

スコア4791

test CHANGED
@@ -63,3 +63,87 @@
63
63
 
64
64
 
65
65
  もし問題があればコメントにてお知らせください。
66
+
67
+
68
+
69
+ ---
70
+
71
+ 追記
72
+
73
+ 使い方として以下のような感じになるでしょう。
74
+
75
+ ```lang-C#
76
+
77
+ public partial class Form1 : Form
78
+
79
+ {
80
+
81
+ public Form1()
82
+
83
+ {
84
+
85
+ InitializeComponent();
86
+
87
+ this.MaximizeBox = false;
88
+
89
+ this.FormBorderStyle = FormBorderStyle.FixedSingle;
90
+
91
+ }
92
+
93
+
94
+
95
+ private void button1_Click(object sender, EventArgs e)
96
+
97
+ {
98
+
99
+ string randomCode = GetHoge();
100
+
101
+ textBox1.Text = randomCode;
102
+
103
+ }
104
+
105
+
106
+
107
+ private static readonly string randomInput = "あいうえお";
108
+
109
+ static string GetHoge()
110
+
111
+ {
112
+
113
+ StringBuilder sb = new StringBuilder();
114
+
115
+ Random r = new Random();
116
+
117
+ //↓文字数固定であればこれを固定値にする
118
+
119
+ int length = r.Next(3, 5); //3~5文字
120
+
121
+ while (sb.Length <= length)
122
+
123
+ {
124
+
125
+ int pos = r.Next(randomInput.Length);
126
+
127
+ char c = randomInput[pos];
128
+
129
+ //↓文字重複させたくない場合
130
+
131
+ //if (sb.ToString().IndexOf(c) >= 0) continue;
132
+
133
+ sb.Append(c);
134
+
135
+ }
136
+
137
+ return sb.ToString();
138
+
139
+ }
140
+
141
+ }
142
+
143
+ ```
144
+
145
+
146
+
147
+ メモ帳的なものに云々については別途質問しなおしたほうが良いでしょう。
148
+
149
+ そのほうが回答がつきやすいと思います。