Best way to randomize an array with .NET

后端 未结 17 872
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 01:55

What is the best way to randomize an array of strings with .NET? My array contains about 500 strings and I\'d like to create a new Array with the same strings b

17条回答
  •  忘了有多久
    2020-11-22 02:41

    Random r = new Random();
    List list = new List(originalArray);
    List randomStrings = new List();
    
    while(list.Count > 0)
    {
    int i = r.Random(list.Count);
    randomStrings.Add(list[i]);
    list.RemoveAt(i);
    }
    

提交回复
热议问题