Xorshift-798 is an efficient 16-bit pseudorandom number generator. The next number in the sequence is produced using three operations where the number is XORed with a shifted copy of itself. The shifts 7, 9 and 8 can be implemented efficiently in assembly using single shifts and swapping bytes. The equivalent C code is:
uint16_t xs = 1;
uint16_t xorshift( )
{
xs ^= xs << 7;
xs ^= xs >> 9;
xs ^= xs << 8;
return xs;
}
More information:
- 16-Bit Xorshift Pseudorandom Numbers in Z80 Assembly at retroprogramming.com
- Xorshift Linear-Feedback Shift Registers on Wikipedia