Files
javaSE-0113/day07/src/com/inmind/random02/Demo05.java

35 lines
880 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.random02;
import java.util.Random;
/*
random类获取随机数
*/
public class Demo05 {
//random类的基本使用
public static void method(String[] args) {
//创建一个随机数生成器对象
Random random = new Random();
//调用random类的方法nextInt方法
for (int i = 0; i < 1000; i++) {
System.out.println(random.nextInt(10));//0~9,java是包头不包尾的
}
}
public static void main(String[] args) {
//获取10个 【55~66包含55和66】之间的随机值
//55~66 - 55 ---> 0~11 ----->random.nextInt(12)
Random random = new Random();
for (int i = 0; i < 100; i++) {
// int val = random.nextInt(12)+55;
int val = random.nextInt(55, 67);//17以上才有
System.out.println(val);
}
}
}