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
658 stars 31 forks source link

could this support deterministic random values? #9

Closed adu-crypto closed 1 year ago

adu-crypto commented 1 year ago

could I specify the randomness source and get deterministic random values?

bxcodec commented 1 year ago

Right now, we use a global var for the randomness source. @wolf-joe please chime in, is it possible to support this?

wolf-joe commented 1 year ago

Right now, we use a global var for the randomness source. @wolf-joe please chime in, is it possible to support this?

Maybe we can pass a seed number to those generate functions by options, but making the seed number work everywhere is difficult.

adu-crypto commented 1 year ago

How about letting these generators share the same seed number? this should be helpful for detecting determinism issues

wolf-joe commented 1 year ago

How about letting these generators share the same seed number? this should be helpful for detecting determinism issues

Oh, I see. There has a global seed number already. You can use SetRandomSource(NewSafeSource(...)) to get the determinism result, like this unit-test.