MIPS assembly - random integer range
Hello im trying to use random integer range and the values that开发者_运维知识库 i get is out ouf the ones that i set.
for example:
sw $a0, 0($s0)
li $a0, 1000
li $a1, 3500
li $v0, 42 #random
So i just want it to be random numbers between 1000-3500 but it gives me any random number.
Can you please help me to understand where my mistake is.
$a0
is the random seed, not the lower bound. You should set $a1
to 2501
to generate 0-2500 random number, and add 1000 to the result.
sw $a0, 0($s0)
li $a1, 2501
li $v0, 42 #random
add $a0, $a0, 1000
精彩评论