Example of random number generator

Página 4/4
1 | 2 | 3 |

Por aoineko

Hero (520)

Imagen del aoineko

19-12-2021, 15:48

I don't know MSX turbo R very well.
I just checked my sample program on OpenMSX using Panasonic FS-A1GT and anything work well.
I haven't looked at how to activate the R800 mode yet but if you're interested, I can take look. It will allow me to start turbo R support for my game library (I was planning to do it later but I can start looking).

Por aoineko

Hero (520)

Imagen del aoineko

19-12-2021, 16:19

OK, I used the BIOS command to switch R800 mode ON.
Here is the result:

The main difference is R800 R register seem to be incremented on a 8-bits base instead of 7-bits for Z80.

Por Grauw

Ascended (10617)

Imagen del Grauw

19-12-2021, 18:19

The Z80 and R800 handle refresh a bit differently. The R register on the Z80 increases by 1 for every M1 cycle (~every instruction), and refresh happens in the second half of every M1 cycle. Whereas on the R800 it increases every ~210 cycles, refresh occurs in bursts which pause the CPU processing.

Por ARTRAG

Enlighted (6862)

Imagen del ARTRAG

20-12-2021, 16:46

aoineko wrote:
ARTRAG wrote:

A faster uniform generator for 7 bit numbers should be :

rand:
                ld   a,r
                ld   b,a
                ld   a,(old_rnd)
                xor  b
                ld   (old_rnd),a
                ret

IMHO seems even more uniform than the first one posted at the beginning of this tread...
Anyone willing confirm my impression?

A "little" late reply, but I have included this version in my test program for the distribution of pseudo-random number generators and the results are very good.

I'm using a fairly close version that I thought was better quality, but in the end I feel like they have the same entropy and the result changes a bit depending on the changes I make in my program (since the R register value depends on the code).

Here is the heatmap for 32765 draws:

You can find other RNG algorithms heatmaps on the MSXVillage (I wanted to put the other images here, but I can't post them on this forum without copying them in a https :-/) : http://msxvillage.fr/forum/topic.php?pt=2&id=1524#m89122

It seems quite uniform to be that simple, very good. Actually a lot of its random behaviour is due to the code around the called function, as R on Z80 is just counting the memory accesses

Por aoineko

Hero (520)

Imagen del aoineko

20-12-2021, 21:54

ARTRAG wrote:

It seems quite uniform to be that simple, very good. Actually a lot of its random behaviour is due to the code around the called function, as R on Z80 is just counting the memory accesses

Yet, I am in one of the worst cases because I am doing two draws in a row for the X and Y axes.
Some other algorithms fail because of this.

The only "issue" I found with this algorithm is that the results are consistent within a build, but not between builds (if the code has changed between calls).
It makes debugging a bit more complex, but the algorithm has such a high speed/efficiency ratio that it's worth it. ^^

Por santiontanon

Paragon (1653)

Imagen del santiontanon

21-12-2021, 04:12

aoineko wrote:

The only "issue" I found with this algorithm is that the results are consistent within a build, but not between builds (if the code has changed between calls).
It makes debugging a bit more complex, but the algorithm has such a high speed/efficiency ratio that it's worth it. ^^

I remember I had a similar debugging problem when I was working on XSpelunker, since the random number generator I was using also depended on the R register. What I ended up doing is to have an alternative version of the generator that was deterministic, and I used for debugging, and then I switched to the one using R only when I was not debugging.

Página 4/4
1 | 2 | 3 |