cpct_getRandom_mxor_u32

Gets a 32-bit pseudo-random number using Marsaglia’s XOR-shift algorithm (using a 32-bits state)

C Definition

u32 cpct_getRandom_mxor_u32 ();

Assembly call

call cpct_getRandom_mxor_u32_asm

Return value (Assembly calls, return DE:HL=random 16-bits)

<u32>Next 32-bits pseudo-random value.

Known limitations

  • This function will never produce a 0 as random 32-bits integer value.  If you require a 0 to be produced, use returned value minus 1.
  • This function does not repeat a single 32-bits value in the sequence it produces until it finishes its period ((2^32)-1).  Use other functions if you require random numbers to sometimes repeat values (which is often desirable)

Details

This function uses cpct_nextRandom_mxor_u32 to produce a sequence of 32-bits pseudo-random numbers.  It uses cpct_mxor32_seed to store the last returned random 32-bits value: this is required to produce the next value in the sequence.

To know more about how these 32-bits numbers are produced, check cpct_nextRandom_mxor_u32 documentation.

Destroyed Register values

AF, BC, DE, HL

Required memory

57 bytes divided in,

Time Measures

   Case     | microSecs (us) | CPU Cycles
-----------------------------------------
    Any     |      67        |    268
-----------------------------------------
unsigned long (u32 = unsigned 32-bits, 4 bytes)
Gets a 32-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.
_cpct_mxor32_seed:: .dw #0x1A7B, #0x59F2
Contains the 32-bits seed for Marsaglia’s XOR-shift random number generator.
Close