戏子痴心猪
一头执着演着戏的猪···

项目中用到过的一个比较实用的方法,在这里做个小小的笔记,方便以后使用。

 

代码
/// <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;
}

 

这个方法虽然是用的list,但是稍稍转换下,也可以用来生成数组。

posted on 2011-01-31 10:23  戏子痴心猪  阅读(350)  评论(0编辑  收藏  举报