LFSR

Post Reply
User avatar
mz-80a
Posts: 403
Joined: Thu Jan 25, 2018 10:46 am
Location: Devon, UK
Contact:

LFSR

Post by mz-80a »

Hi,

I wanted to generate 1000 numbers in a random non-repeating order (ranged between 1 to 1000) and have been given this code which is a linear feedback shift register:

Code: Select all

LD IX,#LFSR ; (2-byte store)
SRL (IX+00)
RR (IX+01)
RET NC
LD A,(IX+00)
XOR #0x02
LD (IX+00),A
LD A,(IX+01)
XOR #0x40
LD (IX+01),A
RET
Just thought it'd be useful to share. I've yet to try it out though but will give it a go soon. I'm unsure how to 'seed' it yet but will work through the code to find out.
MZ-80A Secrets
https://mz-80a.com/

Sharpworks (Sharp MZ homebrew)
https: //mz-sharpworks.co.uk/
User avatar
mz-80a
Posts: 403
Joined: Thu Jan 25, 2018 10:46 am
Location: Devon, UK
Contact:

Re: LFSR

Post by mz-80a »

Yep, it's simply a case of loading the symbol #LFSR with a 16-bit value to start off the number generation process
MZ-80A Secrets
https://mz-80a.com/

Sharpworks (Sharp MZ homebrew)
https: //mz-sharpworks.co.uk/
Post Reply