cpct_restoreState_mxor_u8

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

C Definition

void cpct_restoreState_mxor_u8 ();

Assembly call

call cpct_restoreState_mxor_u8_asm

Known limitations

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

Details

Restores internal index counter of cpct_getRandom_mxor_u8 to its initial value (1).  This ensures that next call to cpct_getRandom_mxor_u8 will produce 32 new random bits.  Therefore, user will be sure that next value returned by cpct_getRandom_mxor_u8 is both pseudo-random generated and predictable (knowing the seed that generates it).

Internal index counter of cpct_getRandom_mxor_u8 is a counter that goes from 4 to 0.  Each time counter gets to 0, cpct_nextRandom_mxor_u32 is called to produce 32 new pseudo-random bits.  If counter is not 0, next group of 8-bits from the last 32 pseudo-random bits is returned, using counter as index.  Therefore, setting this index counter to 1 ensures that next call to cpct_getRandom_mxor_u8 will produce a call to cpct_nextRandom_mxor_u32, obtaining 32 new pseudo-random bits.  This is what this function does.

It is recommended to call this function after cpct_setSeed_mxor to get a proper pseudo-random 8-bits sequence.

Destroyed Register values

A

Required memory

6 bytes +37 bytes of cpct_getRandom_mxor_u8

Time Measures

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