List<Type> 随机排序
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;
}
List<Type> 随机排序的更多相关文章
- Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 原理and实现
Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 1. 应用场景 1 2. 随机抽取数据原理 1 3. 常用的实现方法:::数据库随机函数 1 4. Mssq ...
- JS数组随机排序
var arr=[1,2,3,4,5]; arr.sort(function(a,b){ var v=Math.random()>0.5?1:-1; console.log(a,b,v); re ...
- EF 随机排序
/// <summary> /// 数据上下文扩展 /// </summary> public partial class dbDataContext : IUnitOfWor ...
- LINQ对List列表随机排序,取N条数据
List<Art_Search> artList=new List<Art_Search>(); artList=artList.OrderBy(s => Guid.Ne ...
- js实现数组内元素随机排序
其实蛮容易实现的,关键是简洁与否,下面是我自己写的. function randomSort(a){ var arr = a, random = [], len = arr.length; for ( ...
- JavaScript随机排序算法1
1.对数组循环,每一项与随机的某一项位置调换 <ul id="listOne"></ul> <div id="tempOne"&g ...
- List 随机排序
List<T> l = new List<T>(); l = l.Select(a => new { a, newID = Guid.NewGuid() }).Order ...
- EF架构使用随机排序
c#当中,可以用Random类来获取随机数 EF当中,我们写Linq时,抑或是采用Linq的扩展方法时,发现都没有随机排序的方法,这就要求我们自己去扩展了 引用自http://www.cnblogs. ...
- Unity中List的随机排序(乱序)
为什么要给List排序做一个Unity限定条件呢 首先,是C#中的List泛型,若是Java,直接调用Collection.shuffle()就OK了 而Unity的C#版本较低,不能使用Random ...
- c++随机排序容器中的元素
在各种程序语言中都提供了将容器元素随机排序的shuffle方法,c++也不例外. 不过c++将shuffle放在了<algorithm>中而不是像其他语言一样在random里,同时c++1 ...
随机推荐
- [转]asp.net使用uploadify上传出现的IO Error问题
原文链接:http://blog.csdn.net/w3031213101/article/details/6335878 解决方法:1.uploadify控件的自定义size必须调整大小,即属性:s ...
- 10.Python之Ansible自动化运维常用模块
Ansible中文权威文档:http://www.ansible.com.cn/docs/ Ansible从入门到精通:https://www.bilibili.com/video/av3361175 ...
- Session.Abandon-Session.Clear-Session.RemoveAll
System.Web.UI.Page.Session属性和System.Web.HttpContext.Session属性 都是System.Web.SessionState.HttpSessionS ...
- Working with WordprocessingML documents (Open XML SDK)
Last modified: January 13, 2012 Applies to: Office 2013 | Open XML This section provides conceptual ...
- (一)在HTML页面中实现一个简单的Tab
在HTML页面中实现一个简单的Tab 为了充分利用有限的HTML页面空间,经常会采用类似与TabControl的效果通过切换来显示更多的内容.本文将采用一种最为简单的方法来实现类似如Tab页切换的效果 ...
- java实现wc功能
github项目地址:https://github.com/3216004717/ruanjiangongcheng.git 项目相关要求 基本要求 wc.exe -c file.c //返回文件 f ...
- XE StringGrid应用(G1属性触发G2)
unit UnitMain; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System. ...
- Hackfive 使用TextSwitcher和ImageSwitcher实现平滑过渡
1. 应用场景: 通过向左和向右的导航按钮浏览日期列表 在日期选择空间中改变日期 倒计时始终 新闻刚要 2.用到的知识点是: TextSwitcher和ImageSwitcher Te ...
- C# Path类常用方法
Path 类 对包含文件或目录路径信息的 String 实例执行操作. 1.Path.GetExtension 方法 —— 返回指定的路径字符串的扩展名. public static string G ...
- 649. Dota2 Senate
In the world of Dota2, there are two parties: the Radiant and the Dire. The Dota2 senate consists of ...