1
0
Fork 0
mirror of https://github.com/paricafe/misskey.git synced 2025-04-12 15:49:36 -05:00

use a better random integer generator - fixes

This commit is contained in:
dakkar 2024-11-27 09:33:20 +00:00 committed by fly_mc
parent 7b4fe1a89b
commit 616eb9d14b

View file

@ -14,11 +14,8 @@ export function secureRndstr(length = 32, { chars = LU_CHARS } = {}): string {
let str = '';
for (let i = 0; i < length; i++) {
let rand = Math.floor((crypto.randomBytes(1).readUInt8(0) / 0xFF) * chars_len);
if (rand === chars_len) {
rand = chars_len - 1;
}
str += chars.charAt(rand);
const rand = crypto.randomInt(0, chars_len);
str += chars.charAt(rand);
}
return str;