I\'m creating a simple black jack game using the Easy 68K simulator and need to use a random number to assign the cards. My cards must be in the range 2 to 11. I seem to be gett
You need to use the right mask depending on your interval (minimum and maximum), This code will solve all your problems, it take two arguments : Minimum in D5 and Maximum in D6, it also uses D0, D7 and A1.
RAND_GEN
SUB D5,D6 ;You should give Min in D5 and Max in D6
MOVE D6,D7
ADDI #1,D6
MULU #$FFFF,D7
LEA SEED,A1
MOVE.B #8,d0
TRAP #15
ADD (A1),D1
MULU #$FFFF,D1
EOR.L #$F321F23A,D1
MOVE D1,(A1)
AND.L D7,D1 ;PREVENT OVERFLOW FOR (Max-Min)
DIVU D6,D1 ;time count / (Max-Min)
SWAP D1 ;swap upper and lower words of D1 to put remainder in low word
ADD D5,d1 ;D1.W contains number in the range of (Min,Max)
RTS
* Put variables and constants here
SEED
DC.W 1
The SEED will be by default 1 at the start of program and updates itself automatically after each RAND_GEN call, you can also change it at any time.
Tested on EASY68K.