jeudi 26 août 2021

Can someone explain me why this "random number" is allways the same (1)? [duplicate]

I have one class for showing my GUI called GUI and I have another class called Dice which should do some things for me.

First I only want to add the method createDice() which should create a random number and I want to show it in the console. It shows allways 1 in the console. Please help me. I am new here and I am exited about beeing a part of the community now :)

My Code:

    //returns new dice (number between 1 and 6)
    public int createDice () {
        int dice = (int) Math.random()*6+1;
        return dice;
    }



Aucun commentaire:

Enregistrer un commentaire