Skip to content

Instantly share code, notes, and snippets.

View SethVandebrooke's full-sized avatar

Seth Vandebrooke SethVandebrooke

View GitHub Profile
@SethVandebrooke
SethVandebrooke / random.js
Last active January 22, 2019 15:19
Get a random int, character from a string, item from an array, key or value from an object, or any value between two given ints.
function random(a, b) {
if(Array.isArray(a)){
return a[random(a.length)];
}
if (typeof a === "object") {
var key = random(Object.keys(a));
return b === "key" ? key : b === "both" ? {key:key,value:a[key]} : a[key];
}
if (typeof a === "string" && !!a) {
return (a.toLowerCase() === "bool") ? (Math.floor(Math.random()*2) == 1) : random(a.split(''));