Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.Random;
public class Demo {
static Random randNum = new Random();
public static void main(String args[]) {
System.out.println("Lowercase random letters...");
for (int i = 0; i< 5; i++) {
System.out.println("" + "abcdefghijklmnopqrstuvwxyz".toCharArray()[randNum.nextInt("abcdefghijklmnopqrstuvwxyz".toCharArray().length)]);
}
System.out.println("Uppercase random letters...");
for (int i = 0; i< 5; i++) {
System.out.println("" + "ABCDEFGHIJKLMNOPQRSTUVWZYZ".toCharArray()[randNum.nextInt("ABCDEFGHIJKLMNOPQRSTUVWZYZ".toCharArray().length)]);
}
}
}
import java.util.Random;
public class Demo {
public static final void main(String... args) {
Random randNum = new Random();
System.out.println("Displaying random Booleans...");
for (int i = 1; i<= 5; ++i) {
boolean randomRes = randNum.nextBoolean();
System.out.println(randomRes);
}
}
}
import java.math.BigInteger;
import java.util.Random;
public class Demo {
public static void main(String... a) {
int max = 10;
Random randNum = new Random();
byte[] b = new byte[max];
randNum.nextBytes(b);
// BigInteger type
BigInteger bigInt = new BigInteger(b);
System.out.println("Very large random number = "+bigInt);
}
}