I'm trying to create a complete random number in assembly but it's every time I start the program it gives me the same numbers, in the same order. If the numbers are 12, 132, 4113 or something, it'll repeat them every time I start the code.
The program I'm trying to make is something like a guessing game.
IDEAL
MODEL small
STACK 100h
DATASEG
;vars here
RNG_Seed dw ?
CODESEG
; Generates a pseudo-random 15-bit number.
; Parameters: <none>
; Clobbers: AX, DX
; Returns: AX contains the random number
proc GenerateRandNum
push bx
push cx
push si
push di
; 32-bit multiplication in 16-bit mode (DX:AX * CX:BX == SI:DI)
mov ax, [RNG_Seed]
xor dx, dx
mov cx, 041C6h
mov bx, 04E6Dh
xor di, di
push ax
mul bx
mov si, dx
xchg di, ax
mul bx
add si, ax
pop ax
mul cx
add si, ax
; Do addition
add di, 3039h
adc si, 0
; Save seed
mov [RNG_Seed], di
; Get result and mask bits
mov ax, si
and ah, 07Fh
pop di
pop si
pop cx
pop bx
ret
endp GenerateRandNum
What can I do to get different random numbers every run?
Aucun commentaire:
Enregistrer un commentaire