【发布时间】:2014-10-30 17:49:56
【问题描述】:
我想通过运行一次 exe 生成 5 个 0-9 范围内的随机数。例如,我运行 random.exe 一次,我可以得到 7,1,3,9,2。 我之前使用过下面的代码,但是当你运行 exe 时它只会随机化一次。
mov ah, 00h ; get current time
int 1ah ; cx:dx ---> clock count
mov ax, dx ; move low-order part of clock count to ax
xor dx, dx
mov cx, 10
div cx ; remainder goes to dx (ranges from 0-9)
; dx contains the randomized number
mov ax, dx
call printNum ; prints the contents of ax
我试着把它放在一个循环中,但随机数(dx)没有改变。
【问题讨论】:
-
您的代码运行速度太快,在此期间时钟不会增加。即使是这样,那样也不会是一个随机数。
标签: assembly random numbers masm32