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

Random number seed is always the same on the simulator #85

Closed
microbit-matt-hillsdon opened this issue Oct 31, 2022 · 5 comments · Fixed by #87
Closed

Random number seed is always the same on the simulator #85

microbit-matt-hillsdon opened this issue Oct 31, 2022 · 5 comments · Fixed by #87

Comments

@microbit-matt-hillsdon
Copy link
Contributor

This does't match the device and is unhelpful when teaching random numbers.

https://stackoverflow.com/questions/74077710/microbit-python-random-library-only-generates-one-number

@microbit-matt-hillsdon
Copy link
Contributor Author

We need to implement this stub:

// This is needed by the microbitfs implementation.

Despite the comment, it's only used for the seed in the port config.

We dug into this a bit, and despite CODAL having a random number generator, MicroPython uses its own seeded from CODAL's one (potentially reseeded by the user).

@microbit-carlos
Copy link
Collaborator

Looks like we had a case of:
xkcd random
https://xkcd.com/221/

@microbit-matt-hillsdon
Copy link
Contributor Author

I looked into the other comments from the StackOverflow question:

random.seed doesn't work in the simulator

This seems to work for me, please raise a new issue with an example program if you can reproduce. For the moment, until we fix this issue, the default seed is zero to setting it to that won't affect anything.

machine.reset seems to freeze on the emulator. Will be updating with solution after I test with microbits

This doesn't reproduce straightforwardly, however trying variations on the program on stackoverflow, I raised #86

microbit-matt-hillsdon added a commit that referenced this issue Oct 31, 2022
It's used in a non-crypto safe RNG in MicroPython so just seed it with a
Math.random-derived value.

Closes #85
microbit-matt-hillsdon added a commit that referenced this issue Oct 31, 2022
It's used in a non-crypto safe RNG in MicroPython so just seed it with a
Math.random-derived value.

Closes #85
@microbit-matt-hillsdon
Copy link
Contributor Author

The random seed issue is fixed by #87.

For this change to be available in the Python Editor V3 we still need to release the simulator. I'll do this once we've had a chance to look at the related issue #86.

@microbit-matt-hillsdon
Copy link
Contributor Author

This change is now live in the V3 Python Editor as part of simulator 0.1.6.

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

Successfully merging a pull request may close this issue.

2 participants