diff --git a/src/distribution/Distribution.ts b/src/distribution/Distribution.ts index 5c23359f..63334ea7 100644 --- a/src/distribution/Distribution.ts +++ b/src/distribution/Distribution.ts @@ -1,5 +1,10 @@ import { RandomGenerator } from '../generator/RandomGenerator'; +/** + * Generate random value based on a given RandomGenerator. + * Return the generated value and an offsetted version of the RandomGenerator. + * @public + */ type Distribution = (rng: RandomGenerator) => [T, RandomGenerator]; export default Distribution; export { Distribution }; diff --git a/src/distribution/UniformBigIntDistribution.ts b/src/distribution/UniformBigIntDistribution.ts index eab60030..1228ae9f 100644 --- a/src/distribution/UniformBigIntDistribution.ts +++ b/src/distribution/UniformBigIntDistribution.ts @@ -31,7 +31,24 @@ function uniformBigIntInternal(from: bigint, diff: bigint, rng: RandomGenerator) } } +/** + * Uniformly generate random bigint values between `from` (included) and `to` (included) + * + * @param from - Lower bound of the range (included) + * @param to - Upper bound of the range (included) + * + * @public + */ function uniformBigIntDistribution(from: bigint, to: bigint): Distribution; +/** + * Uniformly generate random bigint values between `from` (included) and `to` (included) + * + * @param from - Lower bound of the range (included) + * @param to - Upper bound of the range (included) + * @param rng - Instance of RandomGenerator to extract random values from + * + * @public + */ function uniformBigIntDistribution(from: bigint, to: bigint, rng: RandomGenerator): [bigint, RandomGenerator]; function uniformBigIntDistribution(from: bigint, to: bigint, rng?: RandomGenerator) { const diff = to - from + BigInt(1); diff --git a/src/distribution/UniformIntDistribution.ts b/src/distribution/UniformIntDistribution.ts index 5b7f9001..e4600b85 100644 --- a/src/distribution/UniformIntDistribution.ts +++ b/src/distribution/UniformIntDistribution.ts @@ -45,7 +45,24 @@ function uniformIntInternal(from: number, diff: number, rng: RandomGenerator): [ } } +/** + * Uniformly generate random integer values between `from` (included) and `to` (included) + * + * @param from - Lower bound of the range (included) + * @param to - Upper bound of the range (included) + * + * @public + */ function uniformIntDistribution(from: number, to: number): Distribution; +/** + * Uniformly generate random integer values between `from` (included) and `to` (included) + * + * @param from - Lower bound of the range (included) + * @param to - Upper bound of the range (included) + * @param rng - Instance of RandomGenerator to extract random values from + * + * @public + */ function uniformIntDistribution(from: number, to: number, rng: RandomGenerator): [number, RandomGenerator]; function uniformIntDistribution(from: number, to: number, rng?: RandomGenerator) { const diff = to - from + 1;