//Random类
package test1;
import java.util.*;
public class Main {
public static void main(String[] args) {
Random r = new Random();
System.out.println("生成Boolean类型的随机数:"+r.nextBoolean());
System.out.println("生成double类型的随机数:"+r.nextDouble());
System.out.println("生成float类型的随机数:"+r.nextFloat());
System.out.println("生成int类型的随机数:"+r.nextInt());
System.out.println("生成long类型的随机数:"+r.nextLong());
System.out.println("生成0-10之间int类型的随机数:"+r.nextInt(10));
System.out.println("生成20-30之间int类型的随机数:"+(20+r.nextInt(10)));
}
}
Output result:
Generate random numbers of Boolean type: true
Generate random numbers of double type: 0.1011389205112806
Generate random numbers of float type: 0.020070255
Generate random numbers of int type: 1309140502
Generate random numbers of long type: -2018860081565599810
Generate between 0-10 Random number of int type: 5
Generate random number of int type between 20-30: 25