reggen icon indicating copy to clipboard operation
reggen copied to clipboard

Support for setting a seed, to allow recreation

Open trabetti opened this issue 5 years ago • 2 comments

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.

trabetti avatar Feb 27 '19 17:02 trabetti

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

smikulcik avatar Dec 17 '19 21:12 smikulcik

I think we can close this since #5 is merged.

onee-only avatar May 23 '24 01:05 onee-only