当前位置:网站首页>[Commons lang3 topic] 002 randomutils topic
[Commons lang3 topic] 002 randomutils topic
2022-07-29 00:58:00 【Zibo Zibo】
【commons-lang3 project 】002- RandomUtils project
List of articles
〇、 Get ready
1、RandomUtils The main role
Provide all kinds of Randomly generate all kinds of data Methods .
2、 Introduce dependencies
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
One 、 Generate int value
1、 Generate [0, Integer.MAX_VALUE) Between random int value
// 1、 Generate [0, Integer.MAX_VALUE) Between random int value
System.out.println(RandomUtils.nextInt()); // 150881120
2、 Generate [startInclusive,endExclusive) Random integer between , The starting value cannot be less than the ending value
// 2、 Generate [startInclusive,endExclusive) Random integer between , The starting value cannot be less than the ending value
System.out.println(RandomUtils.nextInt(10, 20)); // 19
Two 、 Generate boolean value
3、 Randomly generate a Boolean value ,true perhaps false
// 3、 Randomly generate a Boolean value ,true perhaps false
System.out.println(RandomUtils.nextBoolean()); // true
3、 ... and 、 Generate long value
4、 Generate [0, Long.MAX_VALUE) Between long value
// 4、 Generate [0, Long.MAX_VALUE) Between long value
System.out.println(RandomUtils.nextLong()); // 2331387764569299625
5、 Generate [startInclusive,endExclusive) Between random long value
// 5、 Generate [startInclusive,endExclusive) Between random long value
System.out.println(RandomUtils.nextLong(10, 20)); // 12
Four 、 Generate byte array
6、 Generate a specified number of byte arrays
// 6、 Generate a specified number of byte arrays
System.out.println(Arrays.toString(RandomUtils.nextBytes(5))); // [-81, 122, -126, -109, 2]
5、 ... and 、 Generate double value
7、 Generate [0, Double.MAX_VALUE) Between random double value
// 7、 Generate [0, Double.MAX_VALUE) Between random double value
System.out.println(RandomUtils.nextDouble()); // 5.778886902758481E306
8、 Generate [startInclusive,endExclusive) Between random double value
// 8、 Generate [startInclusive,endExclusive) Between random double value
System.out.println(RandomUtils.nextDouble(10, 20)); // 19.05143192281762
6、 ... and 、 Generate float value
9、 Generate [0, Float.MAX_VALUE) Between random float value
// 9、 Generate [0, Float.MAX_VALUE) Between random float value
System.out.println(RandomUtils.nextFloat()); // 5.778886902758481E306
10、 Generate [startInclusive,endExclusive) Between random float value
// 10、 Generate [startInclusive,endExclusive) Between random float value
System.out.println(RandomUtils.nextFloat(10, 20)); // 14.427974
7、 ... and 、 Complete code
package com.zibo.zibo2022.random_utils.main;
import org.apache.commons.lang3.RandomUtils;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
// start
// 1、 Generate [0, Integer.MAX_VALUE) Between random int value
System.out.println(RandomUtils.nextInt()); // 150881120
// 2、 Generate [startInclusive,endExclusive) Random integer between , The starting value cannot be less than the ending value
System.out.println(RandomUtils.nextInt(10, 20)); // 19
// 3、 Randomly generate a Boolean value ,true perhaps false
System.out.println(RandomUtils.nextBoolean()); // true
// 4、 Generate [0, Long.MAX_VALUE) Between long value
System.out.println(RandomUtils.nextLong()); // 2331387764569299625
// 5、 Generate [startInclusive,endExclusive) Between random long value
System.out.println(RandomUtils.nextLong(10, 20)); // 12
// 6、 Generate a specified number of byte arrays
System.out.println(Arrays.toString(RandomUtils.nextBytes(5))); // [-81, 122, -126, -109, 2]
// 7、 Generate [0, Double.MAX_VALUE) Between random double value
System.out.println(RandomUtils.nextDouble()); // 5.778886902758481E306
// 8、 Generate [startInclusive,endExclusive) Between random double value
System.out.println(RandomUtils.nextDouble(10, 20)); // 19.05143192281762
// 9、 Generate [0, Float.MAX_VALUE) Between random float value
System.out.println(RandomUtils.nextFloat()); // 5.778886902758481E306
// 10、 Generate [startInclusive,endExclusive) Between random float value
System.out.println(RandomUtils.nextFloat(10, 20)); // 14.427974
// end
}
}
边栏推荐
- Wechat campus bathroom reservation of small program completion work (6) opening defense ppt
- selenium对接代理与seleniumwire访问开发者工具NetWork
- Selenium docking agent and selenium wire access developer tool network
- DRF -- authentication, authority, frequency source code analysis, global exception handling, automatic generation of interface documents, RBAC introduction
- 小程序毕设作品之微信校园浴室预约小程序毕业设计成品(7)中期检查报告
- 【愚公系列】2022年07月 Go教学课程 020-Go容器之数组
- Copy the table in word to wechat as a picture and send it
- CUDA related
- Outlier detection and open set identification (2)
- Shell programming specifications and variables
猜你喜欢

Some considerations about ThreadPool

数仓搭建——DWT层

靠云业务独撑收入增长大梁,微软仍然被高估?
![[AD learning] the course of PCB drawing in this marine vehicle competition](/img/37/211a0557848f6922fda7a69a114923.png)
[AD learning] the course of PCB drawing in this marine vehicle competition

【AD学习】本次海上航行器大赛画pcb图的历程

状态压缩dp-蒙德里安的梦想

第二轮1000个Okaleido Tiger,再次登录Binance NFT 1小时售罄

分类预测 | MATLAB实现TCN时间卷积神经网络的时序分类预测

小程序毕设作品之微信校园浴室预约小程序毕业设计成品(6)开题答辩PPT

I don't recommend you use Select*
随机推荐
B+ tree~
🧐 Table1 | finish your third line watch in one second
面试突击69:TCP 可靠吗?为什么?
【目标检测】YOLOR理论简介+实践测试VisDrone数据集
UE4 调试常用的打印信息方法
如何给女友讲明白JS的bind模拟实现
Consumer unit 消费单元
Error reporting: when the browser clicks the modify add button, there is no response and no error reporting. Solution
Outlier detection and Gan network (1)
Armeabi-v7a architecture (sv7a)
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
ThinkPHP高仿蓝奏云网盘系统程序
Necessary interview skills for Android (including interview questions and learning materials)
Asynchronous mode worker thread
Api 接口优化的那些技巧
Requestvideoframecallback() simple instance
Jupyter notebook中5个有趣的魔法命令
SDRAM控制器设计(数字控制器的两种设计方法)
(20211130更新)关于jupyter notebook的下载安装及自己的配置、主题
管理区解耦架构见过吗?能帮客户搞定大难题的