Deterministic random number generator seeded by a bytes32 hash
npm install deterministic-diceDeterministic random number generator seeded by a bytes32 hash.
``bash`
npm install deterministic-dice
`typescript
import { DeterministicDice } from "deterministic-dice";
const dice = new DeterministicDice(
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
);
dice.roll(16); // 0-15
dice.roll(6); // 0-5
dice.roll(100); // 0-99
`
1. Initialize with a bytes32 hash (with or without 0x prefix)roll(n)` to get a random number from 0 to n-1 (n possible values)
2. Call
3. Entropy is automatically rehashed with SHA256 when exhausted
4. Same hash always produces the same sequence of rolls
MIT