public static int [] Random(int n)
{
int [] a = new int[n];
for(int i = 0; i < n; i++) a[i] = i + 1;
Random r = new Random();
for(int i = 0; i < n; i++)
{
int m = a[i];
int k = i + r.Next() % (n - i);
a[i] = a[k];
a[k] = m;
}
return a;
}
private void button1_Click(object sender, System.EventArgs e)
{
string s = null;
foreach(int n in Random(Convert.ToInt32(this.textBox1.Text.Trim())))
{
s += n +" ";
}
this.textBox2.Text = s;
}
在textBox1里输入随机数。在textBox2里显示出随机产生的数