public List<int> Randomize(int[] numbers)
{
List<int> randomized = new List<int>();
List<int> original = new List<int>(numbers);
Random r = new Random();
while (original.Count > 0) {
int index = r.Next(original.Count);
randomized.Add(original[index]);
original.RemoveAt(index);
}
return randomized;
}
หรืออีกแบบ
Code (C#)
public List<int> Randomize(int[] numbers)
{
var random = new Random();
List<int> randomized = numbers.OrderBy(x => random.Next()).ToList();
return randomized;
}