Skip to content

Instantly share code, notes, and snippets.

@rhengles rhengles/random.js
Created Nov 27, 2015

Embed
What would you like to do?
setTimeout-based entropy
// please forgive the one letter variables, this is a gist
// the setTimeout must be called sequentially, or else the
// runtime will execute all of them at the same time,
// giving the same value
function random(m, cb) {
var t = Date.now();
setTimeout(function() {
cb(Date.now()-t);
}, m);
}
function randomTimes(x, m, cb) {
function next() {
if ( i == x ) return cb(a);
random(m, function(v) {
a[i] = v;
i++;
next();
});
}
var a = [];
var i = 0;
next();
}
// example
randomTimes(20, 0, function(a) { console.log(a); });
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.