Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 557
Apollon1954 Avatar asked Nov 05 '10 05:11

Apollon1954


People also ask

How generate a random number in Yaml?

YAML is not a programming language and therefore can't generate random numbers.


1 Answers

$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
like image 110
J-16 SDiZ Avatar answered Sep 22 '22 06:09

J-16 SDiZ