@randsum/dice
Version:
A flexible, type-safe dice roller for tabletop RPGs, game development, and probability simulations
14 lines (13 loc) • 436 B
JavaScript
export function coreRandom(max) {
return (Math.random() * max) | 0;
}
export function createSeededRandom(seed = Date.now()) {
let currentSeed = seed;
return function seededRandom(max) {
currentSeed ^= currentSeed << 13;
currentSeed ^= currentSeed >> 17;
currentSeed ^= currentSeed << 5;
const randomValue = Math.abs(currentSeed) / 2147483647;
return (randomValue * max) | 0;
};
}