-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Description
Describe the bug
Methods nextInt and nextLong have inconsistent behaviour. The "max" parameter is exclusive for most of them, but inclusive for one of them.
- nextInt(3): [0, 1, 2] - exclusive
- nextInt(2, 4): [2, 3, 4] - INCLUSIVE
- nextLong(3): [0, 1, 2] - exclusive
- nextLong(2, 4): [2, 3] - exclusive
- nextDouble(2, 3) - exclusive
To Reproduce
@RepeatedTest(100)
void exclusive() {
assertThat(randomService.nextInt(3)).isLessThan(3); // ok
assertThat(randomService.nextInt(1, 3)).isLessThan(3); // fails because 3==3
assertThat(randomService.nextLong(3)).isLessThan(3); //ok
assertThat(randomService.nextLong(1, 3)).isLessThan(3); // ok
assertThat(randomService.nextDouble(2, 3)).isLessThan(3); // ok
}Expected behavior
All these methods should have the same behaviour: either inclusive or exclusive.
I assume exclusive is better because
- most of them are already exclusive
- Standard java methods
java.lang.Random.nextInt(n),java.lang.Random.nextLong(n)are exclusive.
@bodiam @kingthorin What do you choose: inclusive or exclusive?
Versions:
- Faker Version: 1.0 ... 2.4.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels