mercredi 30 août 2017

How to display a specific range of random numbers in java using Math.random [duplicate]

This question already has an answer here:

So, I am fairly new to programming and I started learning about Math.random. I am trying to code a program that will print values in between 4 - 12 but i can't seem to print only the values inside that range. It prints 13 which i don't want to

My Code:

public class MathRandom{
    public static void main(String[] args){

        for(int x = 0; x < 10; x++){ //Just to test what numbers are displayed
        System.out.println((int) (Math.random() * 10) + 4);

        }
    }
}

Did I miss something? thanks in advance for the help




Aucun commentaire:

Enregistrer un commentaire