jeudi 18 février 2016

trying to Math.random()

I'm not too familiar with Math.random(); and I don't know what to do for the conditions that I want. I want to produce a random integer between 0 and 52 so far this is what I have set up.

    public class Tester{
    public static void main(String args[]){
        int size=52;
        while(size>0){
            int rando=(int)Math.random()*size;
            size--;
            System.out.println(rando);
        }
    }
}

My code prints out all 0's until the condition of the while loop is met. I wanted to know how I would produce a random integer between 0 and 52. I understand that Math.random(); produces a double and I think theres a problem with the type casting. Thanks.




Aucun commentaire:

Enregistrer un commentaire