Skip to content

Instantly share code, notes, and snippets.

@tex2e
Created October 28, 2017 10:33
Show Gist options
  • Save tex2e/cfb8698208b724eb53bba70f43098343 to your computer and use it in GitHub Desktop.
Save tex2e/cfb8698208b724eb53bba70f43098343 to your computer and use it in GitHub Desktop.
shuffle array
function rand(min, max) {
if (max === undefined) { max = min; min = 0; }
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function shuffle(array) {
var sample = array.slice(0);
var length = sample.length;
var last = length - 1;
for (var index = 0; index < length; index++) {
var rand = Utils.rand(index, last);
var temp = sample[index];
sample[index] = sample[rand];
sample[rand] = temp;
}
return sample;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment