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

Allow changing RND seed #90

Open
danielreynoldsma opened this issue Nov 15, 2022 · 4 comments
Open

Allow changing RND seed #90

danielreynoldsma opened this issue Nov 15, 2022 · 4 comments

Comments

@danielreynoldsma
Copy link

Currently, RND uses the same seed every time as far as I can tell, as each execution of a program with RND gives the exact same output. Would it be okay to make it so the system time is used as the seed?

@ojwb
Copy link
Collaborator

ojwb commented Nov 20, 2022

The fixed RND seed on startup is a faithful emulation of a real BBC micro, and at least when writing programs aiming to run on BBCMicroBot you really do want that so the results match what the bot will generate.

I suppose there could be an option to randomise it by poking 5 bytes randomly generated by javascript into memory locations 13 to 18 inside the emulator. It needs to happen after BBC BASIC has initialised the RND seed but before the program starts running, so the timing might be a little tricky. Maybe watching for PC being equal to a suitable address inside the BBC BASIC ROM would work.

@mattgodbolt
Copy link
Owner

Agreed @ojwb ; that's an approach that could work and we support that kind of "poke here in that PC" type thing, but don't expose it in a very simple way currently.

@mattgodbolt
Copy link
Owner

Or rather the underlying emulator supports it, I should say!

@ojwb
Copy link
Collaborator

ojwb commented Nov 20, 2022

You can kind of do this inside the emulator actually, e.g.

F.L=13TO18:?L=?-444:N.

That initialises the RND seed to 5 bytes from one of the system VIA timers and gives more random results, but you seem to get one of a subset of values if you e.g. PRINT RND(100) after that - it seems the timer reads tend to return one of a subset of byte values so you don't get a full randomised seed.

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