When rand.Intn()'s arg wraps to a negative number, rand.Intn() panics. When faker.IntBetween(0, math.MaxInt) is used, diff is already MaxInt, so diff+1 causes an integer wraparound and rand.Intn() panics.
Also use math.MaxInt and math.MinInt constants.
Go Version
$ go version
go version go1.21.5 darwin/arm64
Go Tests
$ go test
➜ go test
2023/12/27 16:17:12 Error while requesting https://loremflickr.com/300/200 : request failed
2023/12/27 16:17:12 Error while creating a temp file: temp file creation failed
2023/12/27 16:17:12 Error while requesting https://randomuser.me : request failed
2023/12/27 16:17:12 Error while creating a temp file: temp file creation failed
PASS
ok github.com/jaswdr/faker 4.731s
@sean- I took hover your PR and merged it in #163 applying the fixes to the comments I made. Thank you again for pointing this out, and congratulations for your first PR :tada:
Description
When
rand.Intn()
's arg wraps to a negative number,rand.Intn()
panics. Whenfaker.IntBetween(0, math.MaxInt)
is used,diff
is alreadyMaxInt
, sodiff+1
causes an integer wraparound andrand.Intn()
panics.Also use
math.MaxInt
andmath.MinInt
constants.Go Version
Go Tests