List<Type> 随机排序
2024-08-26 07:40:36
public List<T> GetRandomList<T>(List<T> inputList)
{
//Copy to a array
T[] copyArray = new T[inputList.Count];
inputList.CopyTo(copyArray);
//Add range
List<T> copyList = new List<T>();
copyList.AddRange(copyArray);
//Set outputList and random
List<T> outputList = new List<T>();
Random rd = new Random(DateTime.Now.Millisecond);
while (copyList.Count > 0)
{
//Select an index and item
int rdIndex = rd.Next(0, copyList.Count - 1);
T remove = copyList[rdIndex];
//remove it from copyList and add it to output
copyList.Remove(remove);
outputList.Add(remove);
}
return outputList;
}
最新文章
- CC2540重写按键
- 关于新书《修炼之道:.NET开发要点精讲》的各种说明
- 第二十一篇:SOUI中的控件注册机制
- 改ucosii的中断禁止和恢复代码,这是一个荒谬的错误【 mrs msr】
- promise/bluebird源码
- h5audio标签
- VSCode配置eslint
- [SDOI 2013]方程
- [转]Understanding OpenStack Authentication: Keystone PKI
- 熬之滴水成石:最想深入了解的内容--windows内核机制(6)
- 我和struts2 的第一天
- A “Type Erasure” Pattern that Works in Swift:类型域的转换
- java反射bean to bean
- Application HookMainWindow
- Fragment----静态创建碎片
- (五)动态SQL
- hdu 4435 第37届ACM/ICPC天津现场赛E题
- 撤销正在审核的app
- HDU 3435 A new Graph Game(最小费用最大流)&;amp;HDU 3488
- 工作中遇到的令人头疼的bug