cpct_setSeed_mxor

Sets the new 32-bits seed value for Marsaglia’s XOR-shift random number generator.

C Definition

void cpct_setSeed_mxor (u32 newseed) __z88dk_fastcall;

Input Parameters (4 bytes)

(4B DE:HL) *newseed*New seed to be set for the random number generator.

Assembly call

call cpct_setSeed_mxor_asm

Parameter Restrictions

  • newseed is the new seed byte that will be set internally for Marsaglia’s XOR-shift random number generator.  It should never be set to 0.  Functions that use this seed will always return 0 if this seed is set to 0.

Details

This function sets the internal 32-bits seed used by Marsaglia’s XOR-shift random number generator.  This generator is implemented by the function cpct_nextRandom_mxor_u32 and its internal seed is hold by the variable cpct_mxor32_seed.  This last variable is the one that this function changes.  Under some concrete circumstances, directly setting cpct_mxor32_seed instead of calling this function could be a nice optimization.  However, take into account that this approach could not be portable among different versions of this API.

If you are using cpct_getRandom_mxor_u8 or cpct_getRandom_mxor_u16, only setting the seed will not ensure you get the same sequence.  Depending on the internal index state of this two generators, you may get part of your seed as first random values.  To prevent this from happening, you have to call cpct_restoreState_mxor_u8 or cpct_restoreState_mxor_u16 right after setting the seed with cpct_setSeed_mxor.  This will ensure you get a predictable random sequence.

Setting the mxor seed affects all functions using that seed, namely cpct_nextRandom_mxor_u32, <cpct_nextRandom_mxor_u16> and cpct_nextRandom_mxor_u8.

Destroyed Register values

All preserved

Required memory

8 bytes

Time Measures

   Case     | microSecs (us) | CPU Cycles
-----------------------------------------
    Any     |       14       |    56
-----------------------------------------
Sets the new 32-bits seed value for Marsaglia’s XOR-shift random number generator.
unsigned long (u32 = unsigned 32-bits, 4 bytes)
Calculates next 32-bits pseudo-random number in Marsaglia’s XOR-shift 8-9-23 sequence.
_cpct_mxor32_seed:: .dw #0x1A7B, #0x59F2
Contains the 32-bits seed for Marsaglia’s XOR-shift random number generator.
Gets a high-quality 8-bit pseudo-random number using Marsaglia’s XOR-shift algorithm (Using a 32-bits state)
Gets a high-quality 16-bit pseudo-random number using Marsaglia’s XOR-shift algorithm (using a 32-bits state)
Restores internal index state of Marsaglia’s XORShift 8-bits generator.
Restores internal index state of Marsaglia’s XORShift 16-bits generator.
Calculates next 32-bits state for a Marsaglia’s XOR-Shift pseudo-random 8-bits generator, with the tuple (1,1,3) .
Close