Groups | Search | Server Info | Login | Register
Groups > comp.sys.apple2.programmer > #6315
| Path | csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | kegs@provalid.com (Kent Dickey) |
| Newsgroups | comp.sys.apple2.programmer |
| Subject | Re: Linear Feedback Shift Register |
| Date | Thu, 5 Sep 2024 20:13:09 -0000 (UTC) |
| Organization | provalid.com |
| Lines | 81 |
| Message-ID | <vbd3cl$fbuj$1@dont-email.me> (permalink) |
| References | <vbb26i$1tf0$1@dont-email.me> |
| Injection-Date | Thu, 05 Sep 2024 22:13:10 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="de08fa5dbc9a95f31b2ff3ebde359a57"; logging-data="503763"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q9wGXqTpCBe8LrMimTKy9" |
| Cancel-Lock | sha1:tDT32zJ6IQUAfnrU75L2V64pTow= |
| X-Newsreader | trn 4.0-test76 (Apr 2, 2001) |
| Originator | kegs@provalid.com (Kent Dickey) |
| Xref | csiph.com comp.sys.apple2.programmer:6315 |
Show key headers only | View raw
In article <vbb26i$1tf0$1@dont-email.me>, Duhast <duhast@123gmail.com> wrote: >I'm trying to generate pseudo random numbers 1-255(yes zero is a special >case). Following Graphic Gems, and code I found at codebase64 I came up >with this: > > ORG $300 > > LDY #$00 > >XOR LSR RAND > LDA RAND > BCC SKIP > EOR #$B8 >SKIP STA RAND > STA $2000,Y > INY > BEQ DONE > JMP XOR > >DONE RTS > >RAND DB $01 > >I then put the values in text file: > > 10 D$ = CHR$ (4) > 20 PRINT D$;"OPEN RAND" > 30 PRINT D$;"WRITE RAND" > 40 FOR I = 0 TO 255 > 50 PRINT PEEK (8196 + I) > 60 NEXT > 70 PRINT D$;"CLOSE" > >Pasted them into a spreadsheet and sorted. It doesn't work. There are >missing numbers, duplicate numbers. What am I doing wrong? Is there a >better method? You should use PEEK(8192+I). That may be the only problem. And you can optimize the routine a bit: LOOP LDA RAND LSR BCC SKIP EOR #$B8 SKIP STA RAND STA $2000,Y INY BNE LOOP RTS You don't have to save RAND in a memory location at all, just remove the LDA RAND and STA RAND. It's important for LFSR to start at a non-0 number (if you start it with 0, it stays at 0), so I'd initialize RAND to 1 before the loop. LDA #1 STA RAND You can see it works with a more elaborate code which counts the occurrence of each byte at output: LDY #0 LDA #0 CLR STA $4000,Y INY BNE CLR LDA #1 LOOP LSR BCC SKIP EOR #$b8 SKIP TAX INC $4000,X INY BNE LOOP RTS Where $4000-40ff will have $01 in every position except $4000, and $40B8 will have $02 (something had to occur twice since $00 is not an output). Kent
Back to comp.sys.apple2.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Linear Feedback Shift Register Duhast <duhast@123gmail.com> - 2024-09-04 21:39 -0400
Re: Linear Feedback Shift Register kegs@provalid.com (Kent Dickey) - 2024-09-05 20:13 +0000
Re: Linear Feedback Shift Register Duhast <duhast@123gmail.com> - 2024-09-10 22:54 -0400
Re: Linear Feedback Shift Register kegs@provalid.com (Kent Dickey) - 2024-09-12 03:58 +0000
Re: Linear Feedback Shift Register Duhast <duhast@123gmail.com> - 2024-09-12 19:06 -0400
Re: Linear Feedback Shift Register D Finnigan <dog_cow@macgui.com> - 2024-09-13 00:49 +0000
Re: Linear Feedback Shift Register John Ames <commodorejohn@gmail.com> - 2025-01-16 09:36 -0800
Re: Linear Feedback Shift Register Peter Ferrie <peter.ferrie@gmail.com> - 2025-01-21 15:46 +0000
csiph-web