| |
Wanderer Account closed
Registered: Apr 2003 Posts: 478 |
Random number generation
I've been out of coding for so long that I no longer remember how to generate random numbers.
I remember I used to use a method where I'd pull a note from the SID chip music being played and add on the 'seconds' from the built in clock. It actually worked pretty good for my intentions.
I know BASIC has a RND function, and pardon me for asking but what method would YOU use to obtain a random number. There must be an easier method than what I'm using. I'm looking for an ASSEMBLY method :)
It's been so long, that I really forget all I ever learned :)
|
|
... 11 posts hidden. Click here to view all posts.... |
| |
Tch Account closed
Registered: Sep 2004 Posts: 512 |
Lol,I also used the timer for random numbers.
If you feel like using it again,it is located at $00A2.
That´s the `seconds´ ofcoz.. ;)
|
| |
cadaver
Registered: Feb 2002 Posts: 1160 |
You could also add/eor/shift on bytes from the code. Works best if your codearea is in one place separate from datas. |
| |
Cybernator
Registered: Jun 2002 Posts: 154 |
About SID's wave-output method: just set the 3rd channel to generate noise signal, and mask it with the TEST bit. Then read the output from $d41b or $d41c (I think it was one of these locations). Damn, I must be gettin ol. :( Will turn 20 soonish. Feel free to wish me a happy birthday when time comes. :P
Ok, back on topic: this won't work reliably if Siddy rocks some cool mus coz the 3rd channel has to produce pure noise. But then, it really depends on how random you want your numbers to be. :)
|
| |
Tch Account closed
Registered: Sep 2004 Posts: 512 |
"Damn, I must be gettin ol. :( Will turn 20 soonish."
Aaah,the pain...where is my pension check. ;)
Nice idea,but i recommend running it before the part starts.
Someone mentioned it would be ´daring´ to make something without music,but I disagree.
Music is essential and I am very happy to see so much activity on the SID side of the Commodore! 8)
Anyway,I am happy to see a youngster like yourself,taking interest in this old machine. ;)
|
| |
Wanderer Account closed
Registered: Apr 2003 Posts: 478 |
Quote: "Damn, I must be gettin ol. :( Will turn 20 soonish."
Aaah,the pain...where is my pension check. ;)
Nice idea,but i recommend running it before the part starts.
Someone mentioned it would be ´daring´ to make something without music,but I disagree.
Music is essential and I am very happy to see so much activity on the SID side of the Commodore! 8)
Anyway,I am happy to see a youngster like yourself,taking interest in this old machine. ;)
Thanks for your help. I'm going to try the above suggestions for my upcoming demo :)
|
| |
Hein
Registered: Apr 2004 Posts: 954 |
Quote: About SID's wave-output method: just set the 3rd channel to generate noise signal, and mask it with the TEST bit. Then read the output from $d41b or $d41c (I think it was one of these locations). Damn, I must be gettin ol. :( Will turn 20 soonish. Feel free to wish me a happy birthday when time comes. :P
Ok, back on topic: this won't work reliably if Siddy rocks some cool mus coz the 3rd channel has to produce pure noise. But then, it really depends on how random you want your numbers to be. :)
You can turn off Channel 3 by setting bit 7 on d418 I think. (At least it worked in Goattracker)
But doesnt d41b always output a random number, the moment u turn on c64? |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
The SID noise is also just a simple EOR feedback, you can write that in software aswell. It's propably the best anyway, just use timer/raster/keyboard/SID values as seed and do the rest via a normal random number algorithm.
Example:
ASL rnd
ROL rnd+1
BCC .nofeedback
LDA rnd
EOR #$21
STA rnd
lda rnd+1
EOR #$10
STA rnd+1
.nofeedback: |
| |
MagerValp
Registered: Dec 2001 Posts: 1078 |
The problem with that routine is that if you hit 0, it stays at 0. White Flame posted a neat 8-bit pseudo random routine that walks through all numbers in a sorta-random order, and never gets stuck: http://www.white-flame.com/prng.txt |
| |
Case
Registered: Aug 2002 Posts: 142 |
If you download my "Q-Noter 3" you can find a pretty good random number generating routine in there. |
| |
HCL
Registered: Feb 2003 Posts: 728 |
Waking up this thread again :). Is there any known way to modify the eor-feedback routine (see latest post by Graham) to generate *a bit more* predictable values?.. What i'm after is to have values that increase, but still are a bit random, keeping the property of not missing any values.
What i want to do is a fade-effect which fills the screen with dots/pixels from right to left in a random manner. Something like:
for i=0 to 319
xpos = i + 5*rnd(0)
next i
The above basic shit will of course miss some values and returning other values twice, and.. it's in basic :P. Any ideas? |
Previous - 1 | 2 | 3 - Next |