go-faker / faker

Go (Golang) Fake Data Generator for Struct, previously https://github.com/bxcodec/faker
https://pkg.go.dev/github.com/go-faker/faker/v4
MIT License
614 stars 30 forks source link

Cached cctype results in non-random data #24

Open codingconcepts opened 1 year ago

codingconcepts commented 1 year ago

Issue: The first time faker.CCType() is called, the value is internally cached, meaning subsequent calls will always return the same data:

https://github.com/go-faker/faker/blob/5effebba7fe9e25350305432ffdca5e19151edad/payment.go#L31

Fix: Remove the caching to ensure subsequent calls are sufficiently random.

unrealhoang commented 1 year ago

also this will result in data race issue if multiple faker.CCType() being called for the first time in parallel