@randsum/dice
Version:
A flexible, type-safe dice roller for tabletop RPGs, game development, and probability simulations
23 lines (22 loc) • 741 B
JavaScript
import { coreRandom } from './coreRandom';
import { generateNumericalFaces } from './generateNumericalFaces';
/**
* Generates an array of dice roll results
*
* @param quantity - The number of dice to roll
* @param max - The maximum value (number of sides) for each die
* @param faces - Optional array of custom face values
* @returns An array of roll results
*/
export function coreSpreadRolls(quantity, max, faces) {
const facesArr = faces ?? generateNumericalFaces(max);
const result = new Array(quantity);
for (let i = 0; i < quantity; i++) {
const randomIndex = coreRandom(max);
const face = facesArr[randomIndex];
if (face) {
result[i] = face;
}
}
return result;
}