Skip to content

Instantly share code, notes, and snippets.

@benfrain benfrain/rand.js
Created Jan 30, 2018

Embed
What would you like to do?
Random Array Picker
// Feed it an array and it will return you one entry from the array
function rand(array) {
return array[Math.floor(Math.random() * array.length)];
}
// Example
var sausages = [
"Lincolnshire",
"Cumberland",
"Manchester",
"Pork and Apple"
]
let randomSausage = rand(sausages); // would return a sausage!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.