From 017aaa2ab2fb413124cb9849f3e6415c44601791 Mon Sep 17 00:00:00 2001 From: Carlo van Wyk <5310264+thecarlo@users.noreply.github.com> Date: Tue, 30 Apr 2024 20:58:21 +1000 Subject: [PATCH] randomBytes --- src/functions/passphrase/dice/rollDie.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/functions/passphrase/dice/rollDie.ts b/src/functions/passphrase/dice/rollDie.ts index 1a50374..2082b1f 100644 --- a/src/functions/passphrase/dice/rollDie.ts +++ b/src/functions/passphrase/dice/rollDie.ts @@ -1,3 +1,9 @@ +import { randomBytes } from 'crypto'; + export const rollDie = (): number => { - return Math.floor(Math.random() * 6) + 1; + const buffer = randomBytes(4); + + const randomNumber = buffer.readUInt32BE(0); + + return (randomNumber % 6) + 1; };