reggen
reggen copied to clipboard
Support for setting a seed, to allow recreation
Hi, I have a use case where I am using reggen to generate random strings for my test generator. I need to be able to recreate a test when it fails. For this, I have forked the repository and added a function to set the seed by the user. I suggest to do a PR from my fork.
Until this issue is fixed, I have some unsafe
code to get around this problem:
generator, _ := reggen.NewGenerator(regexPattern)
rRand := reflect.ValueOf(generator).Elem().FieldByName("rand")
reflect.NewAt(rRand.Type(), unsafe.Pointer(rRand.UnsafeAddr())).Elem().Set(reflect.ValueOf(rand.New(rand.NewSource(seed))))
generator.Generate(10)
thx to https://stackoverflow.com/a/43918797
I think we can close this since #5 is merged.