日期:2014-05-18 浏览次数:20777 次
private static void Sort(List<string> list) { Random rm = new Random(); int count = list.Count; int lastIndex = count - 1; for (int i = 0; i < count; i++) { var item = list[lastIndex]; list.RemoveAt(lastIndex); list.Insert(rm.Next(count), item); } }
------解决方案--------------------
就在List1中隨機取值,然後加入到你的其他集合不就好了?有幾個集合就做幾次List1中隨機取值。
------解决方案--------------------
List<string> list1 = new List<string>() { "张三", "李四", "小熊", "小利", "小老" }; Random r=new Random(); var list2 = list1.OrderBy(x => r.Next()).ToList(); var list3 = list1.OrderBy(x => r.Next()).ToList(); Console.WriteLine(string.Join(",", list2)); Console.WriteLine(string.Join(",", list3)); Console.Read();
------解决方案--------------------