cpct_nextRandom_mxorplus_u32

Calculates next 64-bits pseudo-random number using an adaptation of Marsaglia’s XOR-shift+ 128 algorithm to a 64-bits state, using 8-9-23 sequence.

C Definition

u32 cpct_nextRandom_mxorplus_u32 (u8* seed64b) __z88dk_fastcall;

Input Parameters (2 bytes)

(2B HL) *seed64b*Pointer to a 8-bytes (64-bits) vector containing the seed to be used for calculating next random.  This seed will be overwritten with next 64-bits random value.

Assembly call (Input parameter on HL)

call cpct_nextRandom_mxorplus_u32_asm

Parameter Restrictions

  • seed64b could be any 64-bits number except 0.  A 0 as input will always produce another 0 as output.

Known limitations

  • This adaptation of Marsaglia’s XOR-shift+ 128 to 64-bits will never produce a 64-bits 0 value as output.  However, when used to produce 8/16-32-bits values, 0’s will be generated.

Important details

Details

uint32_t s[2] = { 0x12348765, 0xA325BC98 };   // 64-bits non-zero seed
uint32_t xorshift64plus() {
   uint32_t x = s[0];
   uint32_t const y = s[1];
   s[0] = y;
   x ^= x << 8;
   x ^= x >> 9;
   x ^= y ^ (y >> 23);
   s[1] = x;
   return x + y;
}
              [  d   ][  e   ][  h   ][  l   ]
1) XOR        [  e   ][  h   ][  l   ]          ==> Produces d', e', h'
2) XOR                 [  d'  ][  e'  ][  h'  ] ==> Produces h'', l'' (Check notes on e'')
3) XOR [  h'' ][  l'  ]                         ==> Produces d'', e''
-----------------------------------------------
Result        [  d'' ][  e'' ][  h'' ][  l'  ]

Destroyed Register values

AF, BC, DE, HL

Required memory

-- bytes

Time Measures

   Case     | microSecs (us) | CPU Cycles
-----------------------------------------
   Any      |      --        |    ---
-----------------------------------------

Credits

unsigned long (u32 = unsigned 32-bits, 4 bytes)
Calculates next 64-bits pseudo-random number using an adaptation of Marsaglia’s XOR-shift+ 128 algorithm to a 64-bits state, using 8-9-23 sequence.
unsigned char (u8 = unsigned 8-bits, 1 byte )
Close