Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong range for Time randomizers #507

Open
pcuriel opened this issue Aug 29, 2023 · 1 comment
Open

Wrong range for Time randomizers #507

pcuriel opened this issue Aug 29, 2023 · 1 comment
Labels
Milestone

Comments

@pcuriel
Copy link

pcuriel commented Aug 29, 2023

Time randomizers (LocalTimeRandomizer, LocalTimeRangeRandomizer, etc.) do not properly generate values in the expected ranges (up to 23 for hours, 59 for minutes and seconds, etc.), as the upper value is excluded.
The reason for this seems to be in the nextDouble method of AbstractRandomizer which is used under the hoods by these classes. Thus, I suspect even more randomizers may be affected by this.

The bug can be easily reproduced like this.

  @Test
  void hourRandomizerRangeTest() {

    HourRandomizer hourRandomizer = new HourRandomizer();
    int maxHour = IntStream.range(0, 100_000)
      .map(e -> hourRandomizer.getRandomValue())
      .max()
      .orElseThrow();

    assert maxHour == 23 : "Max hour is 23";
  }
@fmbenhassine
Copy link
Member

That's a valid issue. Thank you for reporting it!

@fmbenhassine fmbenhassine added this to the 6.0.0 milestone Oct 1, 2023
irounik pushed a commit to irounik/easy-random that referenced this issue Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants