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

Some issue about class: faker.number: Wrong long integer fake numbers and Not randomly distributed fake numbers #629

Open
2235161562 opened this issue May 17, 2021 · 1 comment

Comments

@2235161562
Copy link

2235161562 commented May 17, 2021

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)
Faker faker1 = new Faker();
Random random = new Random();
for (int i = 0; i <= 3; i  ) {
    //create long integer max and min
	long size = Math.abs(random.nextInt(200));
    long min = Math.abs(random.nextLong());
    long max = min   size;
    System.out.println("min: "   min   "\tmax: "   max);
    
    //create a fake number by number().numberBetween(int min, int max)
    for (int j = 0; j < 10; j  ) {
        long value = faker1.number().numberBetween(min, max);
        System.out.println("found: "   value);
    }
}
//test the distribution of integers made by number().numberBetween(int min, int max)
Faker faker2 = new Faker();
Map<Long, Integer> map = new HashMap<>();
int testCase = 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 (int j = 0; j < testCase; j  ) {
        long r = faker2.number().numberBetween(min, max);
        integer count = map.get(r);
        map.put(r, count == null ? 1 : count   1);
}
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.

10		25
num		count
average	666
10		406
11		918
12		855
13		857
14		836
15		835
16		847
17		846
18		913
19		891
20		832
21		860
22		104

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:

  • OS: Windows
  • JDK: openjdk version "11.0.5" 2019-10-15
  • Faker Version 1.0.1

Additional context
I have fix these issues. I will pull request in a while.

@2235161562
Copy link
Author

2235161562 commented May 17, 2021

I have fixed them in PR #631
--SE_CHWJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant