Yes the short LCG subroutine shown is not correct.
There are some very high quality random number generators that have been written for the z80 at WOS.
The first is a 10^20 period CMWC generator that returns 8-bit random numbers:
http://z88dk.cvs.sourceforge.net/vie...e=text%2Fplain
As you can see it is fast and short. A link to the original thread at WOS can be found in the source code.
The one we use as default generator for rand() in z88dk is a Marsaglia XOR shift generator:
http://z88dk.cvs.sourceforge.net/vie...e=text%2Fplain
32-bits of state is used and the particular (L,R,L) triple is selected for its ease of implementation. Again, the code is fairly fast and short. A link to Marsaglia's paper describing XOR generators is given.
The period is very important especially when you are trying to generate random numbers from a range smaller than what the generator produces. You will see a lot of patterns emerge if the period is small or the generator is weak.
[свернуть]