Line data Source code
1 : import { Distribution } from "../types.ts"; 2 1 : import { add } from "../utils/add.ts"; 3 1 : import { multiply } from "../utils/multiply.ts"; 4 1 : import { realZeroToOneExclusive } from "./realZeroToOneExclusive.ts"; 5 1 : import { realZeroToOneInclusive } from "./realZeroToOneInclusive.ts"; 6 : 7 : /** 8 : * Returns a floating-point value within [min, max) or [min, max] 9 : * @param min The minimum floating-point value, inclusive. 10 : * @param max The maximum floating-point value. 11 : * @param inclusive If true, `max` will be inclusive. 12 : */ 13 0 : export function real( 14 0 : min: number, 15 0 : max: number, 16 0 : inclusive: boolean = false 17 : ): Distribution { 18 0 : if (!isFinite(min)) { 19 0 : throw new RangeError("Expected min to be a finite number"); 20 0 : } else if (!isFinite(max)) { 21 0 : throw new RangeError("Expected max to be a finite number"); 22 0 : } 23 0 : return add( 24 0 : multiply( 25 0 : inclusive ? realZeroToOneInclusive : realZeroToOneExclusive, 26 0 : max - min 27 0 : ), 28 0 : min 29 0 : ); 30 0 : }