日期:2014-05-18 浏览次数:21051 次
可以自己写一个 /// <summary> /// 随机排序 /// </summary> /// <param name="arry"></param> /// <returns></returns> public static int[] RandSort(int[] arry) { int[] arryNew = new int[arry.Length]; Random rnd = new Random(); int n = arry.Length; int i = 0; while (n > 0) { int index = rnd.Next(n); arryNew[i] = arry[index]; arry[index] = arry[n-1]; n--; i++; } return arryNew; } //调用 int[] arry = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] arryRes = RandSort(arry);
------解决方案--------------------
Random r = new Random((int) DateTime.Now.Ticks); var list = Enumerable.Range(0, 99).ToList(); list.Sort((x, y) => r.Next(-1,1));//这一句就行了 list.ForEach(x=>Console.Write(x+"\t")); Console.Read();
------解决方案--------------------
用linq试试,arr = arr.OrderBy(x => rnd.Next())
------解决方案--------------------