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> 随机排序的更多相关文章

  1. Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 原理and实现

    Atitit.并发测试解决方案(2) -----获取随机数据库记录 随机抽取数据 随机排序 1. 应用场景 1 2. 随机抽取数据原理 1 3. 常用的实现方法:::数据库随机函数 1 4. Mssq ...

  2. 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 ...

  3. EF 随机排序

    /// <summary> /// 数据上下文扩展 /// </summary> public partial class dbDataContext : IUnitOfWor ...

  4. LINQ对List列表随机排序,取N条数据

    List<Art_Search> artList=new List<Art_Search>(); artList=artList.OrderBy(s => Guid.Ne ...

  5. js实现数组内元素随机排序

    其实蛮容易实现的,关键是简洁与否,下面是我自己写的. function randomSort(a){ var arr = a, random = [], len = arr.length; for ( ...

  6. JavaScript随机排序算法1

    1.对数组循环,每一项与随机的某一项位置调换 <ul id="listOne"></ul> <div id="tempOne"&g ...

  7. List 随机排序

    List<T> l = new List<T>(); l = l.Select(a => new { a, newID = Guid.NewGuid() }).Order ...

  8. EF架构使用随机排序

    c#当中,可以用Random类来获取随机数 EF当中,我们写Linq时,抑或是采用Linq的扩展方法时,发现都没有随机排序的方法,这就要求我们自己去扩展了 引用自http://www.cnblogs. ...

  9. Unity中List的随机排序(乱序)

    为什么要给List排序做一个Unity限定条件呢 首先,是C#中的List泛型,若是Java,直接调用Collection.shuffle()就OK了 而Unity的C#版本较低,不能使用Random ...

  10. c++随机排序容器中的元素

    在各种程序语言中都提供了将容器元素随机排序的shuffle方法,c++也不例外. 不过c++将shuffle放在了<algorithm>中而不是像其他语言一样在random里,同时c++1 ...

随机推荐

  1. Python3 网络爬虫开发实战学习弱点书签

    1. urllib.robotparse模块对robot.txt文件的解析,can_fetch()方法和parse()方法. Page121 2. lxml.etree模块自动补全Html代码,Htm ...

  2. html5 存储方式

    localstorage(永久保存)&&sessionstorage(重新打开浏览器会消失) sessionStorage用于本地存储一个会话(session)中的数据,这些数据只有在 ...

  3. HTTP文件上传插件开发文档-JSP

    版权所有 2009-2016 荆门泽优软件有限公司 保留所有权利 官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webplug/http-u ...

  4. 第17章-Spring消息

    1 异步消息简介 像RMI和Hessian/Burlap这样的远程调用机制是同步的.如图17.1所示,当客户端调用远程方法时,客户端必须等到远程方法完成后,才能继续执行.即使远程方法不向客户端返回任何 ...

  5. (转)C# HTML解析示例---星星引发的血案

    原文地址:http://www.cnblogs.com/wurang/archive/2013/06/14/3119023.html [前言] 从CSDN转投cnBlog也有一段时间了,发现cnBlo ...

  6. POJ2513 Colored Sticks(Trie+欧拉回路)

    Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some ...

  7. 去掉html标签方法

    public static string CleanHtml(string strHtml) { strHtml = Regex.Replace(strHtml, @"(\<scrip ...

  8. Google Earth 8.0

    前几天有看到全新的Google Earth 8.0升级,刚好适合自己的手机应用.Google Earth 8.0 官方下载:https://play.google.com/store/apps/det ...

  9. Node简单服务器开发

    运用的知识:http,fs,get,post 接口定义:/user?act=reg$user=aaa&pass=bbb后台返回格式:{"ok":false,"ms ...

  10. 使用sshkey,禁用密码登陆,以及git仓库的搭建

    使用sshkey,可以实现免密码登陆服务器,同时关闭ssh service的使用账号密码登陆功能即可 1.首先在客户机添加sshkey(如果是window系统的话需要安装shell终端工具,例如xsh ...