Closed daurnimator closed 6 years ago
Can one not just initialise seedrandom
with a seed to avoid it calling its own internal autoseed()
?
e.g.
const width = 256;
const pool = [];
function tostring(a) {
return String.fromCharCode.apply(0, a);
}
function myAutoseed() {
try {
const out = new Uint8Array(width);
(global.crypto || global.msCrypto).getRandomValues(out);
return tostring(out);
} catch (e) {
const browser = global.navigator;
const plugins = browser && browser.plugins;
return [+new Date(), global, plugins, global.screen, tostring(pool)];
}
}
function main(){
// ...
const rng = seedrandom(myAutoseed());
// ...
}
Released 2.4.4 incorporating pull #46 which should address the strict mode issue.
You define the
global
variable asthis
. https://github.com/davidbau/seedrandom/blob/616a9504fe360d63515c4a051d6d2f3089004329/seedrandom.js#L29This doesn't work in many contexts (particularly if inside of a
"use strict"
); and infact makes your use ofglobal
uninferable by JS tooling.