2022-04-26 20:38:17 +00:00
|
|
|
export let generateFloatRange = (min: number, max: number): number =>
|
2022-04-26 22:59:27 +00:00
|
|
|
Math.random() * (max - min) + min;
|
|
|
|
export let generateIntRange = (min: number, max: number): number =>
|
|
|
|
Math.floor(generateFloatRange(min, max));
|
2022-04-26 18:26:02 +00:00
|
|
|
|
2022-04-26 22:59:27 +00:00
|
|
|
export let generateIntMin = (min: number): number => generateIntRange(min, 100);
|
2022-04-26 20:38:17 +00:00
|
|
|
|
2022-04-26 22:59:27 +00:00
|
|
|
export let generateInt = (): number => generateIntMin(-100);
|
2022-04-26 20:38:17 +00:00
|
|
|
|
2022-04-26 22:59:27 +00:00
|
|
|
let generatePositiveInt = (): number => generateIntMin(1);
|
2022-04-26 18:26:02 +00:00
|
|
|
|
|
|
|
export let generateNormal = (): string =>
|
2022-04-26 22:59:27 +00:00
|
|
|
`normal(${generateInt()}, ${generatePositiveInt()})`;
|
2022-04-26 18:26:02 +00:00
|
|
|
|
|
|
|
export let generateBeta = (): string =>
|
2022-04-26 22:59:27 +00:00
|
|
|
`beta(${generatePositiveInt()}, ${generatePositiveInt()})`;
|
2022-04-26 18:26:02 +00:00
|
|
|
|
|
|
|
export let generateLognormal = (): string =>
|
2022-04-26 22:59:27 +00:00
|
|
|
`lognormal(${generateInt()}, ${generatePositiveInt()})`;
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
export let generateExponential = (): string =>
|
2022-04-26 22:59:27 +00:00
|
|
|
`exponential(${generatePositiveInt()})`;
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
export let generateUniform = (): string => {
|
2022-04-26 22:59:27 +00:00
|
|
|
let a = generateInt();
|
|
|
|
let b = generateIntMin(a + 1);
|
2022-04-26 20:38:17 +00:00
|
|
|
return `uniform(${a}, ${b})`;
|
|
|
|
};
|
2022-04-26 20:05:16 +00:00
|
|
|
export let generateCauchy = (): string => {
|
2022-04-26 22:59:27 +00:00
|
|
|
return `cauchy(${generateInt()}, ${generatePositiveInt()})`;
|
2022-04-26 20:38:17 +00:00
|
|
|
};
|
2022-04-26 20:05:16 +00:00
|
|
|
|
|
|
|
export let generateTriangular = (): string => {
|
2022-04-26 22:59:27 +00:00
|
|
|
let a = generateInt();
|
|
|
|
let b = generateIntMin(a + 1);
|
|
|
|
let c = generateIntMin(b + 1);
|
2022-04-26 20:38:17 +00:00
|
|
|
return `triangular(${a}, ${b}, ${c})`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export let distributions: { [key: string]: () => string } = {
|
|
|
|
normal: generateNormal,
|
|
|
|
beta: generateBeta,
|
|
|
|
lognormal: generateLognormal,
|
|
|
|
exponential: generateExponential,
|
|
|
|
triangular: generateTriangular,
|
2022-04-26 20:05:16 +00:00
|
|
|
cauchy: generateCauchy,
|
2022-04-26 20:38:17 +00:00
|
|
|
uniform: generateUniform,
|
|
|
|
};
|