当前位置:网站首页>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;
边栏推荐
猜你喜欢

Sql Server STUFF与FOR XML PATH

USB virtual serial port (CDC) limit speed test

方法、函数

MySQL的安装

mmdetection3d(2)---结果、log可视化

Arya professional web automated test platform

MySQL optimization summary
![[C language must see] yo, writing bugs, I'm sure you've stepped on the pit](/img/0b/6f0faeb6896824ca94ce7ca983065a.jpg)
[C language must see] yo, writing bugs, I'm sure you've stepped on the pit

【C语言进阶】——剖析入微数据在内存中的存储 【下】(浮点数存储)

es6 Promise
随机推荐
How to bind idea with code cloud
【Unity】三张图让你看懂ShaderGraph编辑器
pycharm连接到远程docker
Grid in pytorch_ How to use sample
[unity scriptable object] tutorial | using scriptable object to store object data information in unity
Point cloud processing voxel filter
禅道项目管理软件,敏捷开发团队不可或缺的工具
【C语言进阶】——剖析入微数据在内存中的存储 【下】(浮点数存储)
编译原理学习笔记3(自上而下语法分析)
2022 idea (student email authentication) installation and use tutorial and basic configuration tutorial
Understanding of virtual (virtual method) in C and its difference from abstract (abstract method)
分支与循环(for与do-while)
【C语言笔记分享】自定义类型:结构体,枚举,联合(建议收藏)
编译原理学习笔记2(语法分析介绍)
2.2-数据类型
[p5.js learning notes] mouse interaction event
点云处理---二叉树
【机器学习笔记】Regularization : Ridge Regression(岭回归)
[unity FPS] tutorial | using unity to make a first person character controller
Can‘t use an undefined value as an ARRAY reference at probe2symbol