用GOTO语句......
没必要这么麻烦吧,你那段函数,如果极限一点说,如果随机出来的一直都是选过的,则为死循环了.
个人评价--很烂!
int[] i = new int[35]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35};
ArrayList result=new ArrayList();
int ran;
Random r=new Random();
for(int j=0;j<7;j++)
{
ran=r.Next(0,35-j);
int res=i[ran];
for(int k=1;k<=7;k++)//检测冲突
{
if(result.Contains(res))
{
res=ran+1;
}
else
{
result.Add(res);
break;
}
}
}
foreach(int m in result)
{
Console.Write(m.ToString()+" ");
}