Skip to content

Commit

Permalink
Restrict random number generator to Bound exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Nov 20, 2024
1 parent a70d0cb commit 0a9839a
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private static String aiGenerated(
}

public static <T extends Number> double getRandomNumber(T bound) {
return random.nextDouble() * bound.doubleValue();
return random.nextDouble() * (bound.doubleValue() - 1);
}

public static <T extends Number> double getRandomNumber(T origin, T bound) {
Expand All @@ -468,7 +468,7 @@ public static <T extends Number> double getRandomNumber(T origin, T bound) {
throw new IllegalArgumentException("Origin must be less than bound");
}

return originValue + random.nextDouble() * (boundValue - originValue);
return originValue + random.nextDouble() * (boundValue - (originValue + 1));
}

public static class Constants {
Expand Down

0 comments on commit 0a9839a

Please sign in to comment.