使用系统调用生成随机数 [英] Generating random numbers using a syscall
本文介绍了使用系统调用生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试生成一个0-99(含)的随机整数,但是在使用42系统调用时,我很难找到它存储值的位置。
I'm trying to generate a random integer from 0-99 (inclusive) but I'm having some difficulty finding where it stores the value to when using the 42 syscall.
到目前为止,我有:
li $a1, 100
li $v0, 42
syscall
我不确定生成的值存储在哪里,所以我可以使用它。 / p>
I'm not sure where the value generated is stored so I can use it though.
推荐答案
来自系统调用帮助页面: $ a0
是伪随机数生成器ID, $ a1
是上限,返回的随机数也将包含在 $ a0
中。
From a syscall help page: $a0
is the pseudorandom number generator id, $a1
is the upper bound, and the returned random number will also be contained in $a0
.
这篇关于使用系统调用生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文