cpct_restoreState_mxor_u16

Restores internal index state of Marsaglia’s XORShift 16-bits generator.

C Definition

void cpct_restoreState_mxor_u16 ();

Assembly call

call cpct_restoreState_mxor_u16_asm

Known limitations

  • This function cannot be used from ROM, as is uses self-modifying code.

Details

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.

Destroyed Register values

A

Required memory

6 bytes +34 bytes of cpct_getRandom_mxor_u16

Time Measures

 Case  | microSecs (us) | CPU Cycles
-----------------------------------------
 any   |       9        |     36
-----------------------------------------
Restores internal index state of Marsaglia’s XORShift 16-bits generator.
Gets a high-quality 16-bit pseudo-random number using Marsaglia’s XOR-shift algorithm (using a 32-bits state)
Sets the new 32-bits seed value for Marsaglia’s XOR-shift random number generator.
Close