c#对一个数组进行打乱顺序
不用在为有没标记这个数据是不是已经被添加过了,这个已经随机生成过了 下次又出现了 怎么办 而烦恼了
public Hashtable NoOrder(int count)
{
ArrayList mylist = new ArrayList();
Hashtable hash = new Hashtable();
Random r=new Random ();
for (int i = 0; i < count; i++)
{
mylist.Add(i);
}
int listcount=mylist.Count;
for (int i = 0; i < listcount; i++)
{
int rand= r.Next(mylist.Count);
hash.Add(mylist[rand],i );
mylist.RemoveAt(rand);
}
return hash;
}
public Hashtable NoOrder(int count)
{
ArrayList mylist = new ArrayList();
Hashtable hash = new Hashtable();
Random r=new Random ();
for (int i = 0; i < count; i++)
{
mylist.Add(i);
}
int listcount=mylist.Count;
for (int i = 0; i < listcount; i++)
{
int rand= r.Next(mylist.Count);
hash.Add(mylist[rand],i );
mylist.RemoveAt(rand);
}
return hash;
}