一个用来快速生成指定大小的随机不重复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;
}
新闻热点
疑难解答