Restores internal index state of Marsaglia’s XORShift 16-bits generator.
void cpct_restoreState_mxor_u16 ();
call cpct_restoreState_mxor_u16_asm
Restores internal of cpct_getRandom_mxor_u16 to its initial value (jump generate). This ensures that next call to cpct_getRandom_mxor_u16 will produce 32 new random bits. Therefore, user will be sure that next value returned by cpct_getRandom_mxor_u16 is both pseudo-random generated and predictable (knowing the seed that generates it).
Internal state of cpct_getRandom_mxor_u16 has 2 possible states: “jump generate” and “no-jump”. First state produces function to jump to its generating code section when called to generate 32 new random bits, returning 16 of those. Next state of the function simply returns the other 16 random bits (hence the no-jump, for not jumping to the generate section). So, restoring the initial state is adding a “JR” instruction at the first byte of the function. That’s what this function does.
It is recommended to call this function after cpct_setSeed_mxor to get a proper pseudo-random 16-bits sequence.
A
6 bytes +34 bytes of cpct_getRandom_mxor_u16
Case | microSecs (us) | CPU Cycles ----------------------------------------- any | 9 | 36 -----------------------------------------