-
Notifications
You must be signed in to change notification settings - Fork 93
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
Seed Support #35
Comments
I was thinking that having an optional import exrex
import random
pattern = r'(A|N)[0-5]{3}'
random.seed(777)
string1 = exrex.getone(pattern)
random.seed(777)
string2 = exrex.getone(pattern)
string1 == string2 # returns True Perhaps, |
The functions used from the random module, in the function called by exrex.getone, could be taken from an instance of random.Random. Once this change is done, setting the seed as proposed by @ghosalya is easy. _rng = random.Random()
def _randone(d, limit=20, grouprefs=None, seed=None):
_rng.seed(seed)
...
_rng.choice(...)
...
def getone(regex_string, limit=20, seed=None):
return _randone(parse(regex_string), limit, seed)
string1 = exrex.getone(pattern, seed=777) It would also be easy to support the solution proposed by @vwyu in a more integrated manner. def seed(seed):
_rng.seed(seed)
pattern = r'(A|N)[0-5]{3}'
exrex.seed(777)
string1 = exrex.getone(pattern)
exrex.seed(777)
string2 = exrex.getone(pattern)
string1 == string2 # returns True |
It would be great if exrex can support seeding when generating a random string from pattern; something like
This should be possible if standard Python's random instance is used
The text was updated successfully, but these errors were encountered: