灰常牛逼的随机数算法

public List<int> CalculateRandom(int maxValue,int num)

{
            List<int> result = new List<int>();
            Random ran = new Random();
            bool isOK = false;
            while (!isOK)
            {
                int key = ran.Next(0, maxValue);// 取最大值
                if (!result.Contains(key))
                {
                    result.Add(key);
                    if (result.Count == num)// 获得了需要的数量
                    {
                        isOK = true;
                    }
                }
            }

    return result;

}

原文地址:https://www.cnblogs.com/luxx/p/1745089.html