Duplicate random numbers

0

I created a class that contains a method that generates a random number from 0 to 61 ... in my Fragment I instantiated within my button event ... My question is, how do I do to put the amount of times it will generate for me. For example, I have spinner with options 1,2,3 so I choose 2, when I click on the button it has to generate for me:

1st = 25 2 = 50

this all at the same time

How would I do it? because if I create each method for the amount of times is difficult, because imagine if the user wants 100 times, then complicates. So how would I do this, I do not have the slightest idea, could anyone help me?

Code:

public void geraSix(){
    MegaSenaController numberRandom = new MegaSenaController();
    numberRandom.megaSena();
    String groupFirst = numberRandom.getPrimary();
    groupText.setText(groupFirst);
}
    
asked by anonymous 28.07.2017 / 15:50

2 answers

1

It was not clear what the methods you created exactly, but following your logic you should store the values in a List and then show them. Ex:

MegaSenaController numberRandom = new MegaSenaController();
int qntNumeros = (int) spinner.getSelectedItem();
List<Integer> numeros = new ArrayList();

for (int aux=0 ; aux<=qntNumeros ; aux++) {
    numberRandom.megaSena();
    numeros.add(numberRandom.getPrimary());  
}

This causes random numbers to be stored in numeros . Then just show them.

    
28.07.2017 / 16:36
0

I believe a loop is resolved:

for (var i = 0, max = max/*neste max voce deve pegar o valor que o usuario quer*/; i < max; i++) {
    //gera um numero aleatorio
}
    
28.07.2017 / 16:39