public static void SetValue()
{
//定义一个7*7的二维数组,定义一个随机函数用来产生随机数,定义一个 ArrayList用来记录产生的随机数
int[,] myArray = new int[7,7];
Random rd = new Random();
ArrayList myList = new ArrayList();
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 7; j++)
{
//随机产生一个1-49的随机数,使用ArrayList存储产生的数字,来验证是否存在重复的数字
int thisValue = rd.Next(1,50);
if (!myList.Contains(thisValue))
{
myList.Add(thisValue);
myArray[i, j] = thisValue;
Console.Write(thisValue+",");
}
//如果产生的数字出现重复则循环产生一个随机数字,直到插入不重复
else
{
do
{
thisValue = rd.Next(1, 50);
} while (myList.Contains(thisValue));
myArray[i, j] = thisValue;
myList.Add(thisValue);
Console.Write(thisValue+",");
}
}
}
}