jeudi 6 septembre 2018

Random r is always the same

Inside the brackets of

public class MainActivity extends AppCompatActivity

I have (among other things):

public float numAlea() {
        return r.nextFloat();
    }

Inside OnCreate I have:

r = new Random();

Then, I have a private void method that starts with

random0to1 = numAlea();

and uses 'random0to1' as if it was a random number, but it seems that this random0to1 is always a number somewhere between 2/3 and 1, because between three buttons that should "pop" randomly each time this private void method is called only the third button is "popped". What is wrong with this code?

Thank you very much for your time!




Aucun commentaire:

Enregistrer un commentaire