simple code block to show Random number
Code: Select all
int pos = rand.nextInt(100);
this is the simple function which returns a random number
The code below gives the random number between 20 and 90
Code: Select all
int min = 20;
int max = 90;
Random r = new Random();
int i1 = r.nextInt(max - min + 1) + min;
nextInt(int max) returns an int between 0 inclusive and max exclusive. so we have to use +1