java random 4 numbers code example
Example 1: java random number
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(50);
n += 1;
Example 2: random numbers java
int random = (int) (Math.random()*(max-min+1)+min);
Example 3: java random 6 digit number
public static String getRandomNumberString() {
Random rnd = new Random();
int number = rnd.nextInt(999999);
return String.format("%06d", number);
}
Example 4: Random number generator in java
public class RandomMethodExample
{
public static void main(String[] args)
{
System.out.println(Math.random());
System.out.println(Math.random());
}
}