Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created May 4, 2019 23:32
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 nbogie/05332f6c8834f6b57a08d8ea1edd911b to your computer and use it in GitHub Desktop.
Save nbogie/05332f6c8834f6b57a08d8ea1edd911b to your computer and use it in GitHub Desktop.
a function which, when given an array of elements, will return one element picked at random from that array.
function pickRandom(arr) {
let ix = Math.floor(Math.random() * arr.length);
return arr[ix];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment