From 486c76e34f22cf1fd66fa2c99e605d52c7077760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= <77127505+xDivisionByZerox@users.noreply.github.com> Date: Mon, 21 Mar 2022 14:14:57 +0100 Subject: fix: mersenne rand invalid input argument (#577) --- src/mersenne.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mersenne.ts b/src/mersenne.ts index 6539d738..521456a1 100644 --- a/src/mersenne.ts +++ b/src/mersenne.ts @@ -22,18 +22,17 @@ export class Mersenne { * Generates a random number between `[min, max)`. * * @param max The maximum number. Defaults to `0`. - * @param min The minimum number. Defaults to `32768`. Required if `max` is set. + * @param min The minimum number. Defaults to `32768`. * * @example * faker.mersenne.rand() // 15515 * faker.mersenne.rand(500, 1000) // 578 */ - rand(max?: number, min?: number): number { - // TODO @Shinigami92 2022-01-11: This is buggy, cause if min is not passed but only max, - // then min will be undefined and this result in NaN for the whole function - if (max === undefined) { - min = 0; - max = 32768; + rand(max = 32768, min = 0): number { + if (min > max) { + const temp = min; + min = max; + max = temp; } return Math.floor(this.gen.genrandReal2() * (max - min) + min); -- cgit v1.2.3