java random usagee code example
Example 1: java random number
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(50);
n += 1;
Example 2: float random class java
import java.util.Random;
public class Example {
public static void main(String[] args) {
Random rd = new Random();
System.out.println(rd.nextFloat());
}
}
Example 3: java random usage
import java.util.Random;
Random rndm = new Random();
int mnmbr = 10;
int rndNumber = rndm.nextInt(mnumber) + 1;
System.out.println(rndNumber);