Random Number, Float, Random Boolean

by rajesh 2009-12-30 16:23:19

To create a Random Number
Random rand = new Random();
int randomNumber = rand.nextInt();



To create a random number less than a value
int n = 10;
int randomNumber = rand.nextInt(n+1);



To create random Float or Long or Boolean
boolean b = rand.nextBoolean();
long l = rand.nextLong();
float f = rand.nextFloat();    
double d = rand.nextDouble(); 


Tagged in:

1210
like
0
dislike
0
mail
flag

You must LOGIN to add comments