Create a gist now

Instantly share code, notes, and snippets.

@surma /randomObject.js Secret
Created Jan 25, 2018

What would you like to do?
function randomString(bytes) {
let arr = new Array(bytes).fill(0);
arr = arr.map(_ => Math.floor(Math.random() * 256));
return btoa(arr);
}
const idLen = 16;
function randomObject(depth, width) {
const r = {};
for(let i = 0; i < width; i++) {
if(depth == 0) {
r[randomString(idLen)] = i;
} else {
r[randomString(idLen)] = randomObject(depth-1, width);
}
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment