deterministic-dice
v2.0.0
Published
Deterministic random number generator seeded by a bytes32 hash
Maintainers
Readme
deterministic-dice
Deterministic random number generator seeded by a bytes32 hash.
Install
npm install deterministic-diceUsage
import { DeterministicDice } from "deterministic-dice";
const dice = new DeterministicDice(
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
);
dice.roll(16); // 0-15
dice.roll(6); // 0-5
dice.roll(100); // 0-99How It Works
- Initialize with a bytes32 hash (with or without
0xprefix) - Call
roll(n)to get a random number from 0 to n-1 (n possible values) - Entropy is automatically rehashed with SHA256 when exhausted
- Same hash always produces the same sequence of rolls
License
MIT
