- ·上一篇文章:C#中获取某月的实际工作日
- ·下一篇文章:使用C#编程实现圆的移动
快速生成指定大小的随机不重复int数组的方法
:2011-02-09 14:17:53
一个用来快速生成指定大小的随机不重复int数组的实用方法
/// <summary>
/// 随机产生考场号
/// </summary>
/// <param name="start">初始值</param>
/// <param name="count">数量</param>
/// <returns></returns>
public static List<int> GetRandomList(int start, int count)
{
List<int> list = new List<int>();
List<int> temp = new List<int>();
for (int i = start; i < count + start; i++)
{
temp.Add(i);
}
Random ro = new Random();
while (list.Count < count)
{
int a = ro.Next(0, temp.Count);
if (!list.Contains(temp[a]))
{
list.Add(temp[a]);
temp.Remove(temp[a]);
}
}
return list;
}
原问地址:http://www.cnblogs.com/13142088/archive/2011/01/31/1948175.html
!
快速生成指定大小的随机不重复int数组的方法