mercredi 13 janvier 2016

Why does int answer = generator.nextInt(10) + 1; only produce numbers between 1 and 10?

I don't understand why it wouldn't generate upwards of 11.

Here is my tester code:

import java.util.Random;

public class randomNumberTest
{
    public static void main(String[] args)
    {
         Random rn = new Random();
         //tests random number generator (between 1(inc) and 10(excl))
         for(int i =0; i < 100; i++)
         {
             int answer = rn.nextInt(10) + 1;
             System.out.println(answer);
         }
    }
}




Aucun commentaire:

Enregistrer un commentaire