| www.retrosoftware.co.uk http://www.retrosoftware.co.uk/forum/ |
|
| What's good for RANDOM? http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=523 |
Page 1 of 1 |
| Author: | PitfallJ [ Thu Oct 21, 2010 11:34 am ] |
| Post subject: | What's good for RANDOM? |
Hi, Anyone know a good hardware address or/and routine to use for random ? I am trying LDA $FE44 but it doesn't seem very random. (saw that in some game) What I ideally need is a random number between 0 and 'N' as well. - PJ |
|
| Author: | RichTW [ Thu Oct 21, 2010 2:28 pm ] |
| Post subject: | Re: What's good for RANDOM? |
You can try combining a load from &FE44 with a circular table of random numbers, e.g. Code: .random ; increment and fetch random number table index LDX randindex INX CPX #16 BCC wrapindex LDX #0 .wrapindex STX randindex ; fetch random number LDA randtable,X EOR &FE44 STA randtable,X RTS .randtable ; put 16 random numbers here If you want to limit the number to between 0 and 2^n-1, that's easily done with an AND. If it's a non-power-of-two, e.g. between 0 and 23, unfortunately I can't think of an easier way than: Code: .try
JSR random AND #31 CMP #24 BCS try |
|
| Author: | PitfallJ [ Wed Dec 01, 2010 9:08 pm ] |
| Post subject: | Re: What's good for RANDOM? |
Thanks for that - the AND trick is pretty neat - I used it in my recent BeebSID game. |
|
| Author: | recycled [ Thu Dec 02, 2010 9:30 am ] |
| Post subject: | Re: What's good for RANDOM? |
I recently used the LSB of the countdown interval timer (wow, I've actually read a manual for this) to pull a random seed for one of my proggies. lda &02A0 Lets not get too involved in how non-random this is going to be 'cause my program is started at exactly the same nano-second after the computer is turned on each time... and then for a fast '8 bit' random number; lsr A bcs skip1 eor #&B2 .skip1 ; random number in accumulator Courtesy of some Commodore programming website I ran into. |
|
| Page 1 of 1 | All times are UTC [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|