#Random number generator
6 messages in this thread
Does anyone have some 68000 assembly code for a "random number" generator
(doesn't have to be AMIGA code)? I have to write a disk excercisor for a
non-AMIGA 68k based machine. Email or a message would be fine. Harry M.
Harry,
Have you looked through the assembly language library? There should be
something there with a random number generator.
Betty
Yes I have, no luck. Tnx – HarryM
There's one in amiga.lib called RangeRand, but that's a C library – I – uh
– liberated it and converted it to register called form so I could use it.
I also have one taken from the Macintosh ROMS, but that on is slower and
longer.. Anyway, the technique is the standard x^ = ((x+j)*k)mod l style.
I'll try to post in next message (hope its short enuf)
* faster more interesting randomizers
* private randomizer from AmigaLib
_RangeRand
MOVEM.L D4/D5,-(SP)
MOVE.W d0,D5 get range
MOVE.W D5,D4 duplicate
SUBQ.W #1,D4 -1
MOVE.L _RangeSeed,D0 get seed
.Loop ADD.L D0,D0 double
BHI.S .skipEor is hi?
EOR.L #$1D872B41,D0
.skipEor
LSR.W #1,D4 divide by 2
BNE.S .Loop
MOVE.L D0,_RangeSeed new Seed
TST.W D5 original number
BNE.S .L3 was it 0?
SWAP D0 yes: no mulu
BRA.S .L4
.L3 MULU D5,D0
.L4 CLR.W D0 eat low order
SWAP D0 return hi order 0..64k
MOVEM.L (SP)+,D4/D5
RTS
_RangeSeed dc.l 0
if you want a file of 'random' numbers, here's a simple suggestion: first
use a compression scheme on any text file you desire, then use any
'encrypt' program on the resulting compressed file. the result of this
two-step process will be a file of fairly good quality random stuff. there
are so many public domain compression and encrypt programs out there that
you may not have to re-invent this wheel, simply have your program
reference an external file of random stuff which you can have any size you
want. it is usually hard to guarantee that a pseudorandom number generator
will go very long without repeating. there is also (if you insist) and
'random' function in the Amiga C language support stuff which I've seen
referenced in the AutoDocs – and I think the .asm version of the algorithm
is also there.