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

Undocumented default seed for PRNG "random" #55

Open
Tikrass opened this issue May 25, 2018 · 0 comments
Open

Undocumented default seed for PRNG "random" #55

Tikrass opened this issue May 25, 2018 · 0 comments

Comments

@Tikrass
Copy link

Tikrass commented May 25, 2018

I am not sure whether this is a noteworthy issue, but I had my problems with it. In the compiler module program.py the seed of the default random.Random instance is set to 0:

    def reset_values(self):
        """ Reset register and memory values. """
        for tape in self.tapes:
            tape.reset_registers()
        self.mem_c = range(USER_MEM + TMP_MEM)
        self.mem_s = range(USER_MEM + TMP_MEM)
        random.seed(0)

I assume that this is for reproducible pseudo-randomness during compilation. However, this also affects the PRNG a user might use in his own program.

I suggest to highlight this behavior somewhere in the documentation, or switch to a custom instance of random.Random wherever reproducible pseudo-randomness is required in the compiler.

More about random.Random: https://docs.python.org/2/library/random.html

I did not test this, but I can imagine that resetting the global seed also has some unwanted side effects, if the compiler.py is called from a Python script, for example for automated compilation.

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