当前位置:网站首页>3.2- random numbers
3.2- random numbers
2022-07-28 17:53:00 【night_ du】
Java The method of obtaining random numbers :
- Use Random Object to obtain random numbers
Specify the interval : min ~ max
int Type integer nextInt(max - min) + min
double Type floating point number nextDouble() * (max - min) + min
Random random = new Random();
// obtain 0-10 A random number between
// from 0-10 Get a random number in the range of int Type of contain 0, But not including 10
int num = random.nextInt(10);
// obtain 10-30 Random integer between
// Gets the random number of the specified interval : min ~ max nextInt(max - min) + min
int num1 = random.nextInt(30 - 10) + 10;
// Get data of floating point type
double num3 = random.nextDouble(); // 0-1 Floating point data between
// Get the floating-point type data of the specified interval
//0 ~ 10 Between
double num4 = random.nextDouble() * (10 - 0) + 0;
// obtain 20 - 50 Floating point data between
double num5 = random.nextDouble() * (50 - 20) + 20;
- Use Math Medium random Method to complete
The result itself is a 0 - 1 Floating point type data between
Specify the interval : min ~ max
double Type floating point data : Math.random() * (max - min) + min
// 0-1 Floating point type data between
double n = Math.random();
// Get the floating-point data of the specified interval
double n1 = Math.random() * (50 - 20) + 20;
边栏推荐
猜你喜欢

7-8 浪漫侧影(25分)建树+新解题思路

es6 Promise

es6 Promise

【C语言笔记分享】自定义类型:结构体,枚举,联合(建议收藏)
![[p5.js learning notes] basic knowledge of code drawing](/img/22/30218278b4663e13bf73b25b3bd66f.png)
[p5.js learning notes] basic knowledge of code drawing

数字滤波器(三)--模拟滤波器的设计

MySQL installation

【C语言笔记分享】字符函数和字符串函数(建议收藏)

Understanding of virtual (virtual method) in C and its difference from abstract (abstract method)
![[unity] three pictures let you understand the shadergraph editor](/img/06/cbb9fc84f17fe8682ffd05e02939c3.png)
[unity] three pictures let you understand the shadergraph editor
随机推荐
.net MVC understanding
[unity] three pictures let you understand the shadergraph editor
How to upload a project to the code cloud using idea
Encapsulation, inheritance, polymorphism
内部类、常用类
MySQL and idea connection
leetcode系统性刷题(二)------贪心、回溯、递归
pycharm连接到远程docker
Database performance analysis and optimization (internal training materials of Aite future team)
点云处理---kd-tree
【p5.js】实战临摹——国际象棋盘
Point cloud processing voxel filter
Mmcv installation method
方法、函数
【C语言进阶】——剖析入微数据在内存中的存储 【下】(浮点数存储)
【Unity】Sprite九宫格到底怎么玩?
[p5.js actual combat] my self portrait
Leetcode systematic question brushing (3) -- binary tree, binary search
Strsplit() function
MySQL installation