类包
import java.util.Random
演示代码
package cn.edu.Lab;
import java.util.Random;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Random r = new Random(); //默认以当前时间作为随机数种子
Scanner scann = new Scanner(System.in);
int n = scann.nextInt();
int k = r.nextInt(n); //随机数范围为[0, n)
System.out.println("随机整数:" + k);
double t = r.nextDouble(); //随机数范围为[0, 1)
System.out.println("随机浮点数:" + t);
scann.close();
}
}