Skip to content

Instantly share code, notes, and snippets.

@surma
Created January 25, 2018 12:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surma/d473bc68902984e6ade4fbe34ed55c3c to your computer and use it in GitHub Desktop.
Save surma/d473bc68902984e6ade4fbe34ed55c3c to your computer and use it in GitHub Desktop.
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