集合随机打乱顺序
2017-03-23 20:05
176 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Random ran = new Random(); List<model> newList = new List<model>(); newList.Add(new model { name="A"}); newList.Add(new model { name = "B" }); newList.Add(new model { name = "C" }); newList.Add(new model { name = "D" }); int index = 0; var temp =new model(); for (int i = 0; i < newList.Count; i++) { index = ran.Next(0, newList.Count - 1); if (index != i) { temp = newList[i]; newList[i] = newList[index]; newList[index] = temp; } } foreach (var item in newList) { Console.Write(item.name); } Console.ReadLine(); } } public class model { public string name { get; set; } } }
相关文章推荐
- java随机打乱集合顺序
- 打乱list集合数据顺序,达到随机显示的目的
- JAVA随机打乱数组顺序的方法
- List集合去除重复元素,不打乱顺序(数组转List)
- 洗牌算法:随机打乱一个数组的顺序
- java 集合的常用操作(排序、查找、打乱顺序)
- 用Collection.shuffle()随机打乱一个顺序数组
- 请从键盘随机输入十个数,保存到List集合中,并分别按倒序和从大到小的顺序输出
- 随机打乱数组(包括二维数组)的顺序-python实现
- 用Collection.shuffle()随机打乱一个顺序数组
- excel打乱各行的顺序,实现无序随机排列
- 一道试题中备选答案打乱顺序,随机展示,用数组实现
- 给定一个数组,要求把数组内元素的顺序随机打乱,然后输出,主要是要保证效率。
- N个整数(数的大小为0-255)的序列,把它们加密为K个整数(数的大小为0-255).再将K个整数顺序随机打乱,使得可以从这乱序的K个整数中解码出原序列。设计加密解密算法,且要求K<=15*N.
- 洗牌算法:随机打乱一个数组的顺序
- jq随机打乱元素顺序
- 将m,n(m>n)的连续自然数序列,打乱顺序重新排列,随机取出一个数,试问取出的这个数是多少?使用一种解法,时间复杂度O(m-n),空间复杂度O(1)
- 洗牌算法:随机打乱一个数组的顺序
- N个整数(数的大小为0-255)的序列,把它们加密为K个整数(数的大小为0-255).再将K个整数顺序随机打乱,使得可以从这乱序的K个整数中解码出原序列。设计加密解密算法,且要求K<=15*N.
- Java基础之随机打乱一个顺序数组