日期:2014-05-18  浏览次数:20777 次

请问,这种随机抽取怎么做
List<string> list1 = new List<string>(){"张三","李四","小熊","小利","小老"};

另外创建一些集合,list2、list3、list4....使得他们都全部添加list1的所有元素,但元素的排列顺序是随机的,

请问,该怎么做?谢谢!!

------解决方案--------------------
C# code
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中隨機取值。
------解决方案--------------------
C# code
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();

------解决方案--------------------
探讨

C# code
List<string> list1 = new List<string>() { "张三", "李四", "小熊", "小利", "小老" };
Random r=new Random();
var list2 = list1.OrderBy(x => r.Next()).ToList();
var li……