package cn.hp.demo4;
import java.util.Random;
public class RandomTest {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
double r = Math.random();
//System.out.println("r =" = r);
int a = (int) Math.round(r*10);
//System.out.println("a =" + a);
//随机x-y的整数
int x=-5,y=15;
int n = (int) Math.round(Math.random()*(y-x)+x);
System.out.println("n = " + n);
//Random类
Random random = new Random();
n = random.nextInt(5);//随机0-4
n = random.nextInt(5)+1;//随机1-5
System.out.println("n = " + n);
}
}
}
Random类
最新推荐文章于 2024-09-10 09:20:22 发布