Fischer Yates shuffle in coffee-script
问题 Assuming that Math.random() produces evenly distributed random numbers between 0 and 1, is this a correct implementation of the Fischer Yates shuffle? I am looking for a very random, even distribution, where the number of shuffled elements in an input array ( arr ) can be specified (as required ). shuffle = (arr, required)-> rnd = (int) -> r = Math.random() * int Math.round r len = arr.length-1 for i in [len..1] random = rnd(i) temp = arr[random] arr[random] = arr[i] arr[i] = temp break if i