int[] array=new int[30];
int a;
Random rd = new Random();
for (int i = 0; i < 30; i++)
{
a=rd.Next(51);
if (array.Contains(a))
i--;
else
array[i] = a;
}
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
int[] intArray = new int[30];
Random random = new Random();
for (int i = 0; i < intArray.Length; i++)
intArray[i] = random.Next(50);
bool result = intArray.Distinct().Count() == intArray.Length; //是否重复。
Console.Write(result);
Console.ReadKey();
vs2008以上版本通过。
http://www.csharpwin.com/csharpspace/8864r1933.shtml