Using the Random metod



The random method is part of the Math class

Random r = new Random();


double n = Math.random(); // returns a decimal between .0000000 and .9999999

double n = Math.random() * 10 ; // returns a number between 0 and 9.99999

int d = (int)(Math.random()*10+1) // returns int between 1 and 10

int d2 = (int)(Math.random()*21 - 10) // returns int between -10 and 10