| |
Style
Registered: Jun 2004 Posts: 498 |
Pseudo-random number generator, set complete?
Hi all
Im looking for an algorithm that will generate random-looking numbers from 1 - 1000, but will only ever select any one number once. Obviously this is for the 64 screen :)
I seem to recall set complete pseudo-random algorithms at uni but cant recall much more. Any advice?
thanks
|
|
... 10 posts hidden. Click here to view all posts.... |
| |
Style
Registered: Jun 2004 Posts: 498 |
Thanks for mentioning LFSR krill. Id never come across them before, but that's exactly what I need. And yep, that looks like what Groep's routine is doing - of course, Ill have to write my own, otherwise Ill have to credit Groep :)
|
| |
chatGPZ
Registered: Dec 2001 Posts: 11386 |
hihi... this routine isnt mine either... or well, the algo isnt :) |
| |
Style
Registered: Jun 2004 Posts: 498 |
pfffft...... dirty ripper
:) |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
or, could use the old linear congruential. Here's x=(x*261+117)%1024:
genRand
; perform rand'=(rand*261+117)%1024
lda rand
asl
rol t4hi ; don't need to init t4hi, as only using bottom two bits
asl
rol t4hi
clc
adc rand
sta rand
lda t4hi
adc rand+1 ;a::rand' is now rand*5
clc
adc rand ;(a::rand')%1024 is now (rand*261)%1024
sta rand+1
clc
lda rand
adc#117
sta rand
lda rand+1
adc#0
and#3
sta rand+1
rts
rand
lda#0
t4hi
brk
(cf http://en.wikipedia.org/wiki/Linear_congruential_generator . The 117's an arbitrary odd number, and the multiplier must be one more than a multiple of four ) |
Previous - 1 | 2 - Next |