mirror of
https://github.com/paricafe/misskey.git
synced 2024-12-28 08:46:43 -06:00
use a better random integer generator - fixes #810
This commit is contained in:
parent
7b4fe1a89b
commit
616eb9d14b
1 changed files with 2 additions and 5 deletions
|
@ -14,10 +14,7 @@ export function secureRndstr(length = 32, { chars = LU_CHARS } = {}): string {
|
||||||
let str = '';
|
let str = '';
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
let rand = Math.floor((crypto.randomBytes(1).readUInt8(0) / 0xFF) * chars_len);
|
const rand = crypto.randomInt(0, chars_len);
|
||||||
if (rand === chars_len) {
|
|
||||||
rand = chars_len - 1;
|
|
||||||
}
|
|
||||||
str += chars.charAt(rand);
|
str += chars.charAt(rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue