-
-
Notifications
You must be signed in to change notification settings - Fork 148
Concurrent data generation (thread safety) #22
Comments
@rdelval can write an example of how you use |
on this topic I've found this discussion |
Sure, the following should trigger
If you run this code with the Thanks for the link, hopefully Go 2 solves this issue. I was able to get this running with the default source without any race conditions. Only issue is the randomness is decreased due to the seed always being the same. |
We can add methods from native package and set seed I put this entry in the general function( func FakeData(a interface{}) error {
rand.Seed(time.Now().UnixNano())
// ... // excerpt
func randomString(n int) string {
b := make([]byte, n)
for i, cache, remain := n-1, rand.Int63(), letterIdxMax; i >= 0; { I did not notice that he did the same ZwbxVNpRjFBVyWfARJTCZRKqS WQJphBDMjQZmYkmrYVgHJWVkM ZrIWzJKnMQrxIUXAuvFaCZFHF zLTjnSfNjILIQfjsXnmakPEAa JExvPuGysQIoZnSlqlCdUGbat @rdelval Do you have any suggestions? |
In this case, to keep the pseudo-randomess it's best to keep a single seed set at the beginning of the initialization and use the default source throughout the rest of the program. I'll raise a PR and we can continue the discussion there. Thanks for looking into this and being receptive to feedback! |
PR #23 |
I'm using faker to generate data for a simulation that has multiple goroutines. It seems faker is currently unable to work with more than a single thread due to the fact that it uses rand.NewSource
here .
The docs say:
https://golang.org/pkg/math/rand/
It would be great to make it so we're able to use faker across multiple threads.
The text was updated successfully, but these errors were encountered: