how to do random in java code example
Example 1: java random number
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(50);
n += 1;
Example 2: how to generate a random number in java
import java.util.Random;
Random rand = new Random();
int maxNumber = 10;
int randomNumber = rand.nextInt(maxNumber) + 1;
System.out.println(randomNumber);
Example 3: generate random number in java
import java.lang.Math;
int randomNumber;
int minimum = 1;
int maximum = 10 - minimum;
randomNumber = (int)((Math.random()*maximum) + minimum);
System.out.println("Random Number (Between 1-10): " + randomNumber);
Example 4: java random usage
import java.util.Random;
Random rndm = new Random();
int mnmbr = 10;
int rndNumber = rndm.nextInt(mnumber) + 1;
System.out.println(rndNumber);
Example 5: java random
int nombreAleatoire = Min + (int)(Math.random() * ((Max - Min) + 1));