Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for setting a seed, to allow recreation #4

Open
trabetti opened this issue Feb 27, 2019 · 2 comments
Open

Support for setting a seed, to allow recreation #4

trabetti opened this issue Feb 27, 2019 · 2 comments

Comments

@trabetti
Copy link
Contributor

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.

@smikulcik
Copy link

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

@onee-only
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants