Sets machine state (seed) for 16-bits Galois Linear-Feedback Shift Register pseudo-random number generator.
void cpct_setSeed_glfsr16 (u16 newseed) __z88dk_fastcall;
(2B HL) newseed | new machine state (seed) to be set as internal state for the G-LFSR random number generator. |
call cpct_setSeed_glfsr16_asm
It sets the seed that 16-bits Galois Linear-Feedback Shift Register (G-LSFR16) will use from now on to produce pseudo-random numbers. This is useful in two main cases:
In the first case, initializing the pseudo-random number generator always with the same seed will produce exactly the same sequence. Producing the same sequence let you repeat a generation completely (for instance, if you are generating a labyrinth, you may generate the same one again). On the contrary, the second case requires the seed to be as random as possible. If you introduce a more-or-less random feed, the sequence will be different each time. For this purpose, you may get pseudo-random inputs like noise coming from cassette tape reader, or time between keypresses of a user while typing input.
With respect to the pseudo-random sequence generated, take into account that G-LSFR16 algorithms implement a 65535 numbers concrete pseudo-random sequence. When you set the seed, you are picking up which one of that 65535 numbers will be the start of the sequence, but that sequence is cyclic. If you want the sequence to have a different internal order, you may use cpct_setTaps_glfsr16 along with one of the 1024 different possible sequences, codified in a TAPSET from <GLFSR16_TAPS>.
All preserved
4 bytes
Case | microSecs (us) | CPU Cycles ----------------------------------------- Any | 8 | 32 -----------------------------------------