当前位置:网站首页>Random list random generation of non repeating numbers
Random list random generation of non repeating numbers
2022-06-25 02:23:00 【Silence, your name】
There is a need , You need to randomly generate six digits , from 100001 ---999999 But without repeating , And it doesn't affect performance . If every time you are born, you can judge whether it is repeated , When enough times are generated , Will affect performance .
I want to open a thread , Handle it in advance . Generate random numbers in advance . Just use it directly
package cn.silence.random;
import cn.hutool.core.util.RandomUtil;
import java.util.ArrayList;
import java.util.List;
public class CodeRandom {
private final List<Integer> list = new ArrayList<>(1000000);
private int index = 0;
public void start() {
while (list.size() < 1000000) {
int code = RandomUtil.randomInt(100000, 999999);
if (!list.contains(code)) {
list.add(code);
}
}
}
public Integer getCode() {
if (index >= list.size()) {
return RandomUtil.randomInt(100000, 999999);
}
return list.get(index++);
}
}
CodeRandom codeRandom = new CodeRandom();
// Start thread
new Thread(codeRandom::start).start();


Take only , Don't delete , So thread safety is not involved . If you delete list Words , The number generated later may cause repetition
边栏推荐
- Hashcat 的使用
- [I.MX6UL] U-Boot移植(六) 网络驱动修改 LAN8720A
- 3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?
- When they are in private, they have a sense of propriety
- Chrysanthemum chain (winter vacation daily question 39)
- 商城项目 pc----商品详情页
- 一线城市软件测试工资——你拖后腿了吗
- 调用系统函数安全方案
- linux上查看mysql的密码_Linux下MySQL忘记密码「建议收藏」
- The ecosystem of the yuan universe
猜你喜欢

当他们在私域里,掌握了分寸感

转行软件测试2年了,给还在犹豫的女生一点建议

Talking about the advantages of flying book in development work | community essay solicitation

Once beego failed to find bee after passing the go get command Exe's pit

做软件安全测试的作用,如何寻找软件安全测试公司出具报告?

File system - basic knowledge of disk and detailed introduction to FAT32 file system

非凸联合创始人李佐凡:将量化作为自己的终身事业

3 years of testing experience. I don't even understand what I really need on my resume. I need 20K to open my mouth?

保险APP适老化服务评测分析2022第06期

Sumati GameFi生态纵览,神奇世界中的元素设计
随机推荐
PE文件基础结构梳理
|遇到bug怎么分析,专业总结分析来了
Sumati GameFi生态纵览,神奇世界中的元素设计
psql 列转行
Sumati gamefi ecological overview, element design in the magical world
测试/开发程序员,30而立,你是否觉得迷茫?又当何去何从......
【移动端】手机界面的设计尺寸
Beescms website penetration test and repair comments "suggestions collection"
数据库系统概论必背知识
记一次beego通过go get命令后找不到bee.exe的坑
Smartctl opens the device and encounters permission denied problem troubleshooting process record
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
当他们在私域里,掌握了分寸感
What are the SQL aggregate functions
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(1)——迁移数据到节点1
linux上查看mysql的密码_Linux下MySQL忘记密码「建议收藏」
Use of hashcat
How to choose a regular and safe foreign exchange trading platform?
EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
02 common codes for Epicor secondary development