jaswdr / faker

:rocket: Ultimate fake data generator for Go with zero dependencies
https://pkg.go.dev/github.com/jaswdr/faker
MIT License
549 stars 59 forks source link

[BUG] v2.0.3 returns incorrect values for Int and UInt methods #164

Closed trentclowater closed 7 months ago

trentclowater commented 8 months ago

Describe the bug Changes made to v2.0.3 seem to have broken the Int and Uint methods. The sample code in the Go Playground will generate the output below (10 random numbers for each method). Only Uint() appears to be working correctly.

Int64: [-9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808]
Int32: [0 0 0 0 0 0 0 0 0 0]
Int16: [0 0 0 0 0 0 0 0 0 0]
Int8: [0 0 0 0 0 0 0 0 0 0]
Int: [-9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854775808]

UInt64: [9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808 9223372036854775808]
UInt32: [0 0 0 0 0 0 0 0 0 0]
UInt16: [0 0 0 0 0 0 0 0 0 0]
UInt8: [0 0 0 0 0 0 0 0 0 0]
UInt: [7656741239857252927 5594207809226113391 6008768823903029407 2021276371439549788 338472662231586328 7331582930402992456 1862095825495157913 6678231846753265959 9208902309648365007 549713215453345498]

They appear to be working more correctly with v2.0.2 (although Int64 and Int do not appear to be producing any negative values with v2.0.2):

Int64: [4457966027044790232 3068793850071510156 4241597960427124847 7097929654138723183 53203214098893531 4549093053679149128 4180637979454261572 7573092381611586563 9173485451690427125 3851087538435533936]
Int32: [-455826018 -1258706307 -1044868518 851197946 -1216443716 515121644 1535424041 -1623242824 -434048819 -921841709]
Int16: [-4581 17178 24303 15499 16902 12949 9880 14951 11319 -6594]
Int8: [-122 100 72 -102 -22 15 -88 -5 110 120]
Int: [7533801517110527743 6978115144997277611 6286691177520792259 4024021042162847838 5061842129050809232 4191043012286955853 3602606074011605235 6839266255701396663 4091504718573783711 4638797404464528346]

UInt64: [41055368818041555 8938590738929278265 1192535113924107347 1668087444309155861 4833168004950273266 790332503801125400 3813344926054000253 1394808423049600791 7440181255669925228 7712871825341992071]
UInt32: [3719961827 1904474432 1215507601 2700000476 1190456603 2950735355 3292251569 3440930050 1848275514 1027039561]
UInt16: [61836 3570 34601 53919 3204 10354 64422 49933 10516 41437]
UInt8: [197 130 112 80 117 215 25 130 68 70]
UInt: [122291367368253944 9184109984619104570 6913572135790214506 4359817097239585374 7179945772768069149 228053568771661241 180971267124051659 832342306344858062 2357607085026279658 1566666409152456504]

To Reproduce See https://goplay.tools/snippet/6eRhDKSKzfW

Expected behavior A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

jaswdr commented 8 months ago

@trentclowater thank you for reporting, I'll check this out.

stephenafamo commented 7 months ago

Did you find some time to take a look at this @jaswdr

edigaryev commented 7 months ago

This seems to be already fixed by https://github.com/jaswdr/faker/pull/165, unfortunately, it's not tagged/released yet.

A quick workaround is to:

go get -u github.com/jaswdr/faker/v2@ae23891d4c901b3603aad44fa0bba41cf0735f84
trentclowater commented 7 months ago

@edigaryev Note that #165 just reverts a fix for a panic that existed originally, so the potential for a panic is still there. The problems with Int64 and Int only returning positive numbers still exists also. So even though it is no longer returning 0 values, it still has some problems.

jaswdr commented 7 months ago

@stephenafamo unfortunately I was not able to got to this.

165 is not released in any version yet because I was still testing it, although in the end we should revert it and re-apply the fix to mitigate the panic. The side effect is that previously the numbers where mostly between 0..100 and now they are much bigger, although this is not a bug I understand that it could break people's code. Fortunately there are many other methods that people can use instead, so my actions items are:

  1. Revert #165 and fix the issue.
  2. Release it as minor version update instead of bug-fix (1.X)
  3. Refer in the release notes to use RandomNumber or IntBetween instead of just Int
jaswdr commented 7 months ago

Released v2.1.0 with fix and tests to avoid this issue. Please @trentclowater check it out and feel free to reopen this issue if needed.