Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
323 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | import crypto from 'crypto';
|
---|
| 2 | const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
|
---|
| 3 |
|
---|
| 4 | let poolPtr = rnds8Pool.length;
|
---|
| 5 | export default function rng() {
|
---|
| 6 | if (poolPtr > rnds8Pool.length - 16) {
|
---|
| 7 | crypto.randomFillSync(rnds8Pool);
|
---|
| 8 | poolPtr = 0;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
---|
| 12 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.