Line data Source code
1 : import { Distribution } from "../types.ts"; 2 1 : import { die } from "./die.ts"; 3 : 4 : /** 5 : * Returns a distribution that returns an array of length `dieCount` of values 6 : * within [1, `sideCount`] 7 : * @param sideCount The number of sides of each die 8 : * @param dieCount The number of dice 9 : */ 10 0 : export function dice( 11 0 : sideCount: number, 12 0 : dieCount: number 13 : ): Distribution<number[]> { 14 0 : const distribution = die(sideCount); 15 0 : return engine => { 16 0 : const result = []; 17 0 : for (let i = 0; i < dieCount; ++i) { 18 0 : result.push(distribution(engine)); 19 0 : } 20 0 : return result; 21 0 : }; 22 0 : }