Skip to content

Commit

Permalink
Improve random.number
Browse files Browse the repository at this point in the history
  • Loading branch information
CMEONE committed Jul 17, 2021
1 parent da6de9b commit e8ca516
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions node/tenvoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,11 @@ function tEnvoy(openpgpRef = openpgp, naclRef = nacl, sha256Ref = sha256) {
} else {
max = parseFloat(max);
}
let random = await this.random.bytes(1).catch((err) => {
let bytes = await this.random.bytes(4).catch((err) => {
reject(err);
});
resolve((random[0] / 255) * (max - min) + min);
let random = (new Uint32Array(bytes.buffer))[0] / 0x100000000;
resolve(random * (max - min) + min);
});
}

Expand Down
5 changes: 3 additions & 2 deletions tenvoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46786,10 +46786,11 @@ function tEnvoy(openpgpRef = openpgp, naclRef = nacl, sha256Ref = sha256) {
} else {
max = parseFloat(max);
}
let random = await this.random.bytes(1).catch((err) => {
let bytes = await this.random.bytes(4).catch((err) => {
reject(err);
});
resolve((random[0] / 255) * (max - min) + min);
let random = (new Uint32Array(bytes.buffer))[0] / 0x100000000;
resolve(random * (max - min) + min);
});
}

Expand Down

0 comments on commit e8ca516

Please sign in to comment.