Skip to content

Commit

Permalink
rollDie: use crypto.getRandomBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
thecarlo committed Apr 30, 2024
1 parent ec9796a commit cc25beb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/functions/passphrase/dice/rollDie.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit cc25beb

Please # to comment.