随机好说,不重复以前一直是while(true)去判断,偶然看到这个方法,for里面两个条件i++写在if里面,从来没有这么用过,记录一下 int[] a = new int[100];
var rand = new Random();
for (int i = 0; i < 100; )
{
var num = rand.Next(0, 101);
if (!a.Contains(num))
{
a = num;
i++;
}
}
Console.WriteLine(string.Join(",",a));
|