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

Bug: unexpected behavior with seed_random #580

Open
guacs opened this issue Aug 17, 2024 · 0 comments
Open

Bug: unexpected behavior with seed_random #580

guacs opened this issue Aug 17, 2024 · 0 comments

Comments

@guacs
Copy link
Member

guacs commented Aug 17, 2024

    name = Use(ModelFactory.__random__.choice, ["rule", "group_rule", "misc_rule"])
    color = Use(ModelFactory.__random__.choice, ["green", "red", "purple"])
    type = Use(ModelFactory.__random__.choice, ["input", "checkbox", "list", "link"])

shouldn't ModelFactory.seed_random(10) make the above work?

it only works doing like @Alc-Alc said

    name = lambda: RuleFactory.__random__.choice(["rule", "group_rule", "misc_rule"])
    color = lambda: RuleFactory.__random__.choice(["green", "red", "purple"])
    type = lambda: RuleFactory.__random__.choice(["input", "checkbox", "list", "link"])

But this gives an warning: https://docs.astral.sh/ruff/rules/lambda-assignment/ and it's a little bit ugly.

Originally posted by @JobaDiniz in #578 (reply in thread)

The use of Use doesn't result in deterministic behavior even if one calls BaseFactory.seed_random(some_seed). This is due to how we're implementing seed_random. We create a new Random instance with the given seed instead of reseeding the existing instance. This means that the cls.random.choice function that's referenced is the method associated with the Random instance before we call seed_random. Thus, you don't get the deterministic behavior.

This should be fixed so that seed_instance reseeds the existing random instance we have instead of creating a new one.


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
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

1 participant