diff options
| author | Leyla Jähnig <[email protected]> | 2022-03-21 14:14:57 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-21 13:14:57 +0000 |
| commit | 486c76e34f22cf1fd66fa2c99e605d52c7077760 (patch) | |
| tree | b31135d4cb91689521d7d357764447c68b1eed03 /src | |
| parent | c51fb1570669284e14915916636de97b7f644e17 (diff) | |
| download | faker-486c76e34f22cf1fd66fa2c99e605d52c7077760.tar.xz faker-486c76e34f22cf1fd66fa2c99e605d52c7077760.zip | |
fix: mersenne rand invalid input argument (#577)
Diffstat (limited to 'src')
| -rw-r--r-- | src/mersenne.ts | 13 |
1 files changed, 6 insertions, 7 deletions
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); |
