The method of obtaining random number Random class object method java 0913
Random class
Instantiate this class to get an object
Use object methods to get integers
Code
import java.util.Random;
public class test {
public static void main(String[] args) {
Random random = new Random();
// 测试随机出来的结果范围
for(int i=0;i<20;i++){
int res = random.nextInt(3);
System.out.print(res);
}
}
}
effect
22012221000112211022
in conclusion
NextInt of the random object (integer parameter)
Can get 0 to integer parameter -1, integer
video
https://www.ixigua.com/6871841743608906254?logTag=HyaquIQxNlY-Nj0FpsOqo