Calculates next 32-bits state for a Marsaglia’s XOR-Shift pseudo-random 8-bits generator, with the tuple (5,3,2).
u32 cpct_nextRandom_mxor532_u8 (u32 seed) __z88dk_fastcall;
(4B DE:HL) *state* | Previous state that the XOR-Shift algorithm will use to calculate its follower in the sequence. |
call cpct_nextRandom_mxor532_u8_asm
<u32> | Next internal state of the pseudo-random generator. The 8 Least Significant bits of this state are the 8 pseudo-random bits generated by this call. |
This function implements a sequence of 32-bits states with period (2^32)-1. For each produced state, a random sequence of 8-bits is returned. This means that it produces consecutive 8-bits values that do not repeat until 4.294.967.295 numbers have been generated. To do this, the function receives a 32-bit state as parameter (that should be different from 0) and returns the next 32-bit value in the sequence. In each returned state, the 8 Least Significant bits are the 8 pseudo-random bits produced.
The sequence calculated by this function is based on a modified version of Marsaglia’s XOR-shift generator using the tuple (5, 3, 2) for 8-bit values. Assuming that the 32-bits state s is composed of 4 8-bits numbers s=(x, z, y, w), this algorithm produces a new state s’=(x’,z’,y’,w’) doing these operations:
x' = y; y' = z; z' = w; t = x ^ (x << 2); t = t ^ (t >> 3); w' = w ^ (w << 5) ^ t;
where <</>> are left/right bit shifting operations, and ^ is the exclusive OR (XOR) bitwise operation.
AF, BC, DE, HL
24 bytes
Case | microSecs (us) | CPU Cycles ----------------------------------------- Any | 26 | 104 -----------------------------------------