notes_20on_20the_20use_20of_20rnd
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes_20on_20the_20use_20of_20rnd [2022/07/29 13:14] – Changed sort% to sort%% for compatibility with BBCSDL richardrussell | notes_20on_20the_20use_20of_20rnd [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 66: | Line 66: | ||
As mentioned above, the sequence-length of BBC BASIC' | As mentioned above, the sequence-length of BBC BASIC' | ||
- | When //BBC BASIC for Windows// is executed the random number generator is seeded from the value of [[http:// | + | When //BBC BASIC for Windows// or //BBC BASIC for SDL 2.0// is executed the random number generator is seeded from the CPU Performance Counter: a 64-bit integer value which counts at a rate up to the clock speed of the CPU. |
- | + | ||
- | To improve the performance you should seed the generator yourself, using the **RND(-n)** option. To do better than the automatic seeding you need to choose a value which is highly variable, not predictable and can range over most or all of the available range (-2147483648 to -1). On a Windows PC a suitable source of such a seed is the Performance Counter: a 64-bit integer value which counts at a rate up to the clock speed of the CPU. The following code may be used: | + | |
- | + | ||
- | <code bb4w> | + | |
- | DIM pc{l%,h%} | + | |
- | SYS " | + | |
- | seed% = RND(-ABS(pc.l%)-1) | + | |
- | </ | + | |
It should be noted, however, that the rate at which the Performance Counter increments is extremely variable between systems, and indeed one isn't guaranteed to exist at all. Therefore if you are lucky enough to have a better source of seed available you should use that instead. | It should be noted, however, that the rate at which the Performance Counter increments is extremely variable between systems, and indeed one isn't guaranteed to exist at all. Therefore if you are lucky enough to have a better source of seed available you should use that instead. | ||
notes_20on_20the_20use_20of_20rnd.1659100467.txt.gz · Last modified: 2024/01/05 00:16 (external edit)