Generating random words in MIPS

559 Views Asked by At

I want to generate random words in MIPS. I know how to generate random numbers, I just want a random word from a word bank. I have tried this but I have no idea how to print them.

.data
### WORD BANK ###
a0:     .asciiz "computer"
b1:     .asciiz "processor"
c2:     .asciiz "motherboard"
d3:     .asciiz "graphics"
e4:     .asciiz "network"
f5:     .asciiz "ethernet"
g6:     .asciiz "memory"
h7:     .asciiz "microsoft"
i8:     .asciiz "linux"
j9:     .asciiz "transistor"
k10:    .asciiz "antidisestablishmentarianism"
l11:    .asciiz "protocol"
m12:    .asciiz "instruction"
word:   .word   a0,b1,c2,d3,e4,f5,g6,h7,i8,j9,k10,l11,m12

.text
la $To,word

How may I choose a random word from a given list?

2

There are 2 best solutions below

0
On

You could create an Array, then with a forEach Loop with inside an object that generates a random numbers, you display the word of the array that corresponds to random generated number.

THIS IS JAVA CODE, BUT I HOPE IT MIGHT HELP

import java.util.Random;

//main class
public class Test1 
{

public static void main(String[] args) 
{       
    //Array of names
    String[] wordBank = {"luca", "serena", "giuseppe", "nicole", "eleonora", "elena", "matteo"};

    //random generation of names
    for(int i=1; i<10; ++i)
    {
        Random dice = new Random();
        int dice2 = dice.nextInt(6);
        System.out.println(wordBank[dice2]);    
    }

}

}

0
On

If you have a randomly generated number n in the range of int, find the index of your number using the remainder of n divided by word bank size (in this case, 13). If you have an upper bound for the RNG set it to the word bank size. Then just load the string using the index from memory.