You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug #458 find a bug about the range of number().numberBetween(int min, int max). But there are more bugs in number().numberBetween(int min, int max). The long number faker can not correctly make the long integer in number().numberBetween(int min, int max).
In additions, the fake number made by number().numberBetween(int min, int max) is not randomly and evenly distributed.
//test long integers made by number().numberBetween(long min, long max)Fakerfaker1 = newFaker();
Randomrandom = newRandom();
for (inti = 0; i <= 3; i ) {
//create long integer max and minlongsize = Math.abs(random.nextInt(200));
longmin = Math.abs(random.nextLong());
longmax = minsize;
System.out.println("min: "min"\tmax: "max);
//create a fake number by number().numberBetween(int min, int max)for (intj = 0; j < 10; j ) {
longvalue = faker1.number().numberBetween(min, max);
System.out.println("found: "value);
}
}
//test the distribution of integers made by number().numberBetween(int min, int max)Fakerfaker2 = newFaker();
Map<Long, Integer> map = newHashMap<>();
inttestCase = 100000, min = 10, max = 25;
System.out.println(min"\t\t"max);
System.out.println("num\t\tcount");
System.out.println("average\t" (testCase / (max - min)));
for (intj = 0; j < testCase; j ) {
longr = faker2.number().numberBetween(min, max);
integercount = map.get(r);
map.put(r, count == null ? 1 : count1);
}
for (Map.Entry<Long, Integer> entry : map.entrySet()) {
System.out.println(entry.getKey() "\t\t"entry.getValue());
}
To Reproduce
for test 1: even make an Exception in number().numberBetween(int min, int max)
min: 1062082946916230716 max: 1062082946916230855
found: 1062082946916230784 (it is valid number)
found: 1062082946916230784
found: 1062082946916230912
found: 1062082946916230784
found: 1062082946916230784
found: 1062082946916230656
found: 1062082946916230656
found: 1062082946916230784
found: 1062082946916230784
found: 1062082946916230912
min: 4971341182321149360 max: 4971341182321149523
found: 4971341182321148928 (it is less than min = 4971341182321149360)
found: 4971341182321148928
found: 4971341182321148928
found: 4971341182321149952
found: 4971341182321148928
found: 4971341182321148928
found: 4971341182321148928
found: 4971341182321149952
found: 4971341182321149952
found: 4971341182321149952
min: 5569810202729802020 max: 5569810202729802058
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
at com.github.javafaker.service.RandomService.nextLong(RandomService.java:34)
at com.github.javafaker.Number.decimalBetween(Number.java:164)
at com.github.javafaker.Number.numberBetween(Number.java:145)
for test 2: Not only there are much less counts for num 10 and num 22, But also the count of 23 and 24 is 0.
Describe the bug
#458 find a bug about the range of
number().numberBetween(int min, int max)
. But there are more bugs innumber().numberBetween(int min, int max)
. The long number faker can not correctly make the long integer innumber().numberBetween(int min, int max)
.In additions, the fake number made by
number().numberBetween(int min, int max)
is not randomly and evenly distributed.To Reproduce
for test 1: even make an Exception in
number().numberBetween(int min, int max)
for test 2: Not only there are much less counts for num 10 and num 22, But also the count of 23 and 24 is 0.
Expected behavior
For test 1:
min: AAAA max: BBBB
found: XXXX (AAAA<=XXXX<BBBB)
For test 2:
10 25
num count
average 666
10 AAA (Close to 666)
......
24 BBB (Close to 666)
Versions:
Additional context
I have fix these issues. I will pull request in a while.
The text was updated successfully, but these errors were encountered: