Jump to content

Knuth shuffle: Difference between revisions

m
Line 2,646:
for (i = arr.length - 1; i > 0; i -= 1) {
rand = Math.floor((i + 1) * Math.random());//get random between zero and i (inclusive)
temp = arr[rand];//swap i and the zero-indexed number
arr[rand] = arr[i]; //swap i (last element) with random element.
arr[i] = temp;
}
Line 2,673:
3,1,2 16460
3,2,1 16596</pre>
 
 
===ES6===
1

edit

Cookies help us deliver our services. By using our services, you agree to our use of cookies.