Skip to content

Commit

Permalink
Merge ac49b9c into 5dc0124
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 26, 2020
2 parents 5dc0124 + ac49b9c commit d470203
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/distribution/Distribution.ts
Original file line number Diff line number Diff line change
@@ -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<T> = (rng: RandomGenerator) => [T, RandomGenerator];
export default Distribution;
export { Distribution };
17 changes: 17 additions & 0 deletions src/distribution/UniformBigIntDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<bigint>;
/**
* 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);
Expand Down
17 changes: 17 additions & 0 deletions src/distribution/UniformIntDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>;
/**
* 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;
Expand Down

0 comments on commit d470203

Please sign in to comment.