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

First random number always the same #255

Open
jasperp92 opened this issue Nov 15, 2023 · 3 comments
Open

First random number always the same #255

jasperp92 opened this issue Nov 15, 2023 · 3 comments

Comments

@jasperp92
Copy link

The block "random int" generates the same pseudo random number after reset. It looks like it shows the seed, but has not generated a random number yet.

@kreutel
Copy link

kreutel commented Nov 16, 2023

Fount that one too. The RNG gets seeded identically every time - or not at all. Anyway: The sequence of random numbers is always the same.

@Amerlander
Copy link
Collaborator

I'm working on it. Choosing the calliope mini 1 template should still give random numbers.

@Amerlander
Copy link
Collaborator

Amerlander commented Nov 17, 2023

I'm working on it. Choosing the calliope mini 1 template should still give random numbers.

Sorry, I was talking about the beta version.

Seems related to the bluetooth stack. I Can reproduce it on the microbit when I load ble: https://makecode.microbit.org/S81402-73332-20016-17530
In the beta version bluetooth is only loaded for mini 2 and mini 3 devices, that's why the mini 1 template shows random numbers.

The random seed generation falls back to a static seed if ble is enabled: https://github.com/calliope-edu/codal-microbit-v2/blob/dc0383b581156ef8196202b299a629c6c29d6ba9/source/MicroBitDevice.cpp#L67

Usually, the ubit.init() function should generate the seed before ble actually starts, so that should not be an issue.
I also was not able to reproduce this issue using the samples with enabled ble.
I also tried to generate a random seed by sensor data when ble is enabled, but this has no effect: https://github.com/calliope-edu/codal-microbit-v2/blob/beed355baa7308c176aeef4ea5e316ddcc74f7a8/model/MicroBit.cpp#L215

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