获取不重复的随机数数组

在网上找的资料

int[] intArr = GetRandom1(1, 100000, 10000);

/// <summary>
/// 获取不重复的随机数数组
/// </summary>
/// <param name="minValue">最小值</param>
/// <param name="maxValue">最大值</param>
/// <param name="count">数量</param>
/// <returns></returns>
public static int[] GetRandom1(int minValue, int maxValue, int count)
{

Random rnd
= new Random();
int length = maxValue - minValue + 1;
byte[] keys = new byte[length];
rnd.NextBytes(keys);
int[] items = new int[length];
for (int i = 0; i < length; i++)
{
items[i]
= i + minValue;
}
Array.Sort(keys, items);
int[] result = new int[count];
Array.Copy(items, result, count);
return result;

}
原文地址:https://www.cnblogs.com/smartsensor/p/2031731.html