int[] numbers=new int [20]; //建立一个数组
Random rand=new Random (); //生成随机数
string result=""; //保存结果
for (int i = 0; i < 20; i++) //初始化数组
numbers[i] = i+1;
for (int i = 0; i < 20; i++) //洗牌
{
int temp = rand.Next(20);
int tempNumber = numbers[i ];
numbers[i] = numbers[temp ];
numbers[temp] =tempNumber ;
}
for (int i = 0; i < 4; i++) //这个用来排列你想要的那4个数
for (int j = 0; j < 4; j++)
{ //你不需要就去掉它
int temp;
if (numbers[i] < numbers[j])
{
temp = numbers[j];
numbers[j] = numbers[i];
numbers[i] = temp;
}
else
continue;
} //生成结果项
for (int i = 0; i < 4; i++)
result += "result" + i.ToString() + "==>" + numbers[i].ToString() + Environment.NewLine;
MessageBox.Show(result ); //输出结果
转载于:https://www.cnblogs.com/Yellowshorts/archive/2013/02/19/2917090.html