当前位置:网站首页>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
边栏推荐
- Jetson Nano 从入门到实战(案例:Opencv配置、人脸检测、二维码检测)
- Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification
- [mobile terminal] design size of mobile phone interface
- beescms网站渗透测试和修复意见「建议收藏」
- 【直播回顾】战码先锋第七期:三方应用开发者如何为开源做贡献
- 文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍
- Logminer database log mining
- Redistemplate operates redis. This article is enough (I) [easy to understand]
- 【第26天】给定 n 个元素的升序数组nums,求实现一个函数在nums中寻找target的下标 | 初识二分查找
- 常用的软件测试工具清单,请查收。
猜你喜欢
![[analysis of STL source code] functions and applications of six STL components (directory)](/img/f2/872fd93ef52b1424343ba634be24f6.png)
[analysis of STL source code] functions and applications of six STL components (directory)

EasyCVR平台EHOME协议接入,视频播放出现断流是什么原因?

背了八股文,六月赢麻了……

文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍

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

谈谈飞书对开发工作的优势 | 社区征文

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

Use of hashcat

业务与技术双向结合构建银行数据安全管理体系

yarn : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
随机推荐
入坑机器学习:一,绪论
字符串数组转换为list集合
DDD concept is complex and difficult to understand. How to design code implementation model in practice?
当人们用互联网式的思维和视角来看待产业互联网的时候,其实已陷入到了死胡同
The role of software security testing, how to find a software security testing company to issue a report?
Specific list of regular and safe domestic stock trading account opening
Viewing MySQL password on Linux_ MySQL forgets password "suggestions collection" under Linux
|How to analyze bugs? Professional summary and analysis
Test / development programmers, 30, do you feel confused? And where to go
Processon producer process (customized)
如何通过EasyCVR接口监测日志观察平台拉流情况?
算力服务网络:一场多元融合的系统革命
Qt中使用QDomDocument操作XML文件
yarn : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\yarn.ps1,因为在此系统上禁止运行脚本
AI服装生成,帮你完成服装设计的最后一步
Computing service network: a systematic revolution of multi integration
商城项目 pc----商品详情页
June 24, 2022: golang multiple choice question, what does the following golang code output? A:1; B:3; C:4; D: Compilation failed. package main import ( “f
Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
Pit entry machine learning: I. Introduction