We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bc9d4ed commit 7f1af04Copy full SHA for 7f1af04
src/rng.js
@@ -1,7 +1,12 @@
1
import crypto from 'crypto';
2
3
-const rnds8 = new Uint8Array(16);
+const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
4
+let poolPtr = rnds8Pool.length;
5
6
export default function rng() {
- return crypto.randomFillSync(rnds8);
7
+ if (poolPtr > rnds8Pool.length - 16) {
8
+ crypto.randomFillSync(rnds8Pool);
9
+ poolPtr = 0;
10
+ }
11
+ return rnds8Pool.slice(poolPtr, (poolPtr += 16));
12
}
0 commit comments