mattgodbolt / owlet-editor

A modern BBC BASIC editor inspired by the BBC Micro Bot (https://bbcmicrobot.com)
https://bbcmic.ro
54 stars 4 forks source link

Allow changing RND seed #90

Open danielreynoldsma opened 2 years ago

danielreynoldsma commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

ojwb commented 2 years ago

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.