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

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Reflect ...

  2. SVN常见问题及解决方式(一)

    1.每天早上上班要update SVN,每天下班要commit SVN.2.查看是谁动了我的代码,右键 tortoise 后查看 log 日志.3.文件被别人删除,在空白处右击,show log,可以 ...

  3. HTTP Modules versus ASP.NET MVC Action Filters

    from:http://odetocode.com/blogs/scott/archive/2011/01/17/http-modules-versus-asp-net-mvc-action-filt ...

  4. poj1860 Currency Exchange(spfa判断正环)

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  5. Extjs Hello extjs

    <html > <head runat="server"> <title></title> <link rel="s ...

  6. C#上位机中ZedGraph控件的使用

    上位机程序控制PLC模拟量通道输出周期性正弦波信号,并采集所造成改变的模拟量输入信号,并绘制数据变化曲线. 界面如图: 最后测试效果如图: 代码: using System; using System ...

  7. 第二篇:git创建流程

    1.创建组织 2.创建 3.点击项目 创建完: 4.选择管理——>选择公钥——>添加个人公钥: 5.怎样生成公钥 5.1.如何生成ssh公钥 你可以按如下命令来生成 sshkey: ssh ...

  8. CLion中出现错误add_dependencies called with incorrect number of arguments解决

    出现这个错误以后我以为是IDE出现问题了,可是重新启动,打开其他的工程文件以后发现并没有这个错误,但是新建的文件却报错 然后就打开其他工程的Cmake_list.txt文件,发现最后一行是有工程文件夹 ...

  9. django中如何建立抽象型数据库作为父模块可继承其功能

    先建立抽象数据库 from django.db import models class BaseModel(models.Model): """为模型类补充字段" ...

  10. vue2.0使用ES6语法

    ES6 快速入门 什么是ES6? ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了.Mozilla公司将在这个标准的基础上,推出Java ...