标签:nts str int and nbsp next element array blog
把数组内的元素随机打乱,重新进行排列
C#版:
1 public static void Shuffle<T>(T[] array) 2 { 3 Random random = new Random(); 4 5 for (int i = 0; i < 10; i++) 6 { 7 int idx = random.Next(i, 10); 8 9 //swap elements 10 T tmp = array[i]; 11 array[i] = array[idx]; 12 array[idx] = tmp; 13 } 14 }
标签:nts str int and nbsp next element array blog
原文地址:http://www.cnblogs.com/xinxin521/p/6115693.html