icrowley / fake

Fake data generator for Go (Golang)
MIT License
591 stars 77 forks source link

Feature request: Set custom seed for pseudo-random generator. #3

Open smyrman opened 8 years ago

smyrman commented 8 years ago

I guess all that would be needed, would be to expose a method:

 // SetSource lets you customize the source used for generating random numbers.
 func SetSource(src rand.Source) {
   r = rand.New(src)
}
smyrman commented 8 years ago

My particular use case for adding it would be to allow reproduce benchmarks or test results by setting the seed. Allowing to set the rand.Source opens up for more use cases than just allowing to set the seed, so better to expose SetSource than to expose a SetSeed function;-)

smyrman commented 8 years ago

From the discussion on #1, I presume it probably make sense to wrap the provided src in a lockedSource insatance to make it thread safe.

corpix commented 7 years ago

Thats make sense. I will be making a huge refactoring in a few weeks, there will be a constructor to create a custom faker instance with rand.Source from arguments.

fgrosse commented 7 years ago

fyi this issue seems related to the merged PR #15 which allows you to seed the RNG.