curfmanm@prism.CS.ORST.EDU (Matthew Curfman) (01/31/91)
| Hi all. I am looking for a way to generate random numbers in an assembly | language program. The entry point to the applesoft RND function would | be a start, but I really just need an algorithm. I'm using one that | shifts a 2-byte seed left once and adds it back to the seed. that doesn't | give very good results after the first few numbers. | | thanks | | greg c489030@umcvmb.missouri.edu The following routine has worked for everything I have ever needed: 300: 4c 07 03 JMP 0307 303: 27 0c a1 c9 (Random Seeds) 307: ad 06 03 LDA 0306 30a: 0a ASL 30b: 0a ASL 30c: 0a ASL 30d: 4d 06 03 EOR 0306 310: 0a ASL 311: 0a ASL 312: 2e 03 03 ROL 0303 315: 2e 04 03 ROL 0304 318: 2e 05 03 ROL 0305 31b: 2e 06 03 ROL 0306 31e: 60 RTS Call the routine, and then an 8-bit random number can be then pulled from $0304 by your application. While this routine simulates a random number, it does in fact repeat after several million numbers. It is based on an article in Radio Electronics by Don Lancaster in his Hardware Hacker column. _______________________________________________________________________________ Matt Curfman Technovelty. Inc. curfmanm@prism.cs.orst.edu Oregon State University OSU says what it says. I say what I say. We don't say the same thing. _______________________________________________________________________________ Matt Curfman Technovelty. Inc. curfmanm@prism.cs.orst.edu Oregon State University OSU says what it says. I say what I say. We don't say the same thing.
curfmanm@mist.cs.orst.edu (Matthew Curfman) (01/31/91)
| Hi all. I am looking for a way to generate random numbers in an assembly | language program. The entry point to the applesoft RND function would | be a start, but I really just need an algorithm. I'm using one that | shifts a 2-byte seed left once and adds it back to the seed. that doesn't | give very good results after the first few numbers. | | thanks | | greg c489030@umcvmb.missouri.edu The following routine has worked for everything I have ever needed: 300: 4c 07 03 JMP 0307 303: 27 0c a1 c9 (Random Seeds) 307: ad 06 03 LDA 0306 30a: 0a ASL 30b: 0a ASL 30c: 0a ASL 30d: 4d 06 03 EOR 0306 310: 0a ASL 311: 0a ASL 312: 2e 03 03 ROL 0303 315: 2e 04 03 ROL 0304 318: 2e 05 03 ROL 0305 31b: 2e 06 03 ROL 0306 31e: 60 RTS Call the routine, and then an 8-bit random number can be then pulled from $0304 by your application. While this routine simulates a random number, it does in fact repeat after several million numbers. It is based on an article in Radio Electronics by Don Lancaster in his Hardware Hacker column. _______________________________________________________________________________ Matt Curfman Technovelty. Inc. curfmanm@prism.cs.orst.edu Oregon State University OSU says what it says. I say what I say. We don't say the same thing. -- _______________________________________________________________________________ Matt Curfman Technovelty. Inc. curfmanm@mist.cs.orst.edu Oregon State University OSU says what it says. I say what I say. We don't say the same thing.