Skip to content

Instantly share code, notes, and snippets.

@fuchao2012
Last active February 24, 2017 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuchao2012/da222ababcd0c71cbe8700fee0dc1f4c to your computer and use it in GitHub Desktop.
Save fuchao2012/da222ababcd0c71cbe8700fee0dc1f4c to your computer and use it in GitHub Desktop.
Random Array
//Fisher-Yates 舒服了
Array.prototype.shuffle=function(){
let results = [], temp, acc = this.length >>> 0
while(acc > 0){
temp = (Math.random() * acc--)>>>0
[this[acc],this[temp]] = [this[temp], this[acc]]
}
return this
}
//Little Shuffle
Array.prototype.shuffle = function(){
return this.sort(()=>.5 - Math.random())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment