From cc25beb7285c9df3c26aa1cc8a6adb0bd96dccec Mon Sep 17 00:00:00 2001 From: Carlo van Wyk <5310264+thecarlo@users.noreply.github.com> Date: Tue, 30 Apr 2024 20:53:35 +1000 Subject: [PATCH] rollDie: use crypto.getRandomBytes --- src/functions/passphrase/dice/rollDie.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/functions/passphrase/dice/rollDie.ts b/src/functions/passphrase/dice/rollDie.ts index 523b103..2082b1f 100644 --- a/src/functions/passphrase/dice/rollDie.ts +++ b/src/functions/passphrase/dice/rollDie.ts @@ -1,7 +1,9 @@ +import { randomBytes } from 'crypto'; + export const rollDie = (): number => { - const array = new Uint8Array(1); + const buffer = randomBytes(4); - crypto.getRandomValues(array); + const randomNumber = buffer.readUInt32BE(0); - return (array[0] % 6) + 1; + return (randomNumber % 6) + 1; };