Skip to content

Commit

Permalink
refactor: swap values when min is bigger max
Browse files Browse the repository at this point in the history
  • Loading branch information
xDivisionByZerox authored and ST-DDT committed Mar 21, 2022
1 parent d4ff46e commit 6388b4e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mersenne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class Mersenne {
*/
rand(max = 32768, min = 0): number {
if (min > max) {
throw new Error('Invalid input: "min" cannot be bigger than "max".');
const temp = min;
min = max;
max = temp;
}

return Math.floor(this.gen.genrandReal2() * (max - min) + min);
Expand Down

0 comments on commit 6388b4e

Please sign in to comment.