当前位置:网站首页>生成随机数(4位、6位)
生成随机数(4位、6位)
2022-07-01 14:20:00 【海蓝时见鲸-】
public class RandomUtils {
private static final Random random = new Random();
private static final DecimalFormat fourdf = new DecimalFormat("0000");
private static final DecimalFormat sixdf = new DecimalFormat("000000");
public static String getFourBitRandom() {
return fourdf.format(random.nextInt(10000));
}
public static String getSixBitRandom() {
return sixdf.format(random.nextInt(1000000));
}
/** * 给定数组,抽取n个数 * @param list * @param n * @return */
public static ArrayList getRandom(List list, int n) {
HashMap<Object, Object> hashMap = new HashMap<>();
for (int i = 0; i < list.size(); i++) {
int number = random.nextInt(100) + 1;
hashMap.put(number, i);
}
Object[] objs = hashMap.values().toArray();
ArrayList<Object> r = new ArrayList<>();
for (int i = 0; i < n; i++) {
r.add(list.get((int) objs[i]));
System.out.println(list.get((int) objs[i]) + "\t");
}
System.out.println("\n");
return r;
}
}
边栏推荐
- Basic operation of queue (implemented in C language)
- Journal MySQL
- Après avoir été licencié pendant trois mois, l'entrevue s'est effondrée et l'état d'esprit a commencé à s'effondrer.
- Advanced C language
- 使用 Lambda 函数URL + CloudFront 实现S3镜像回源
- 【IoT毕设.上】STM32+机智云AIoT+实验室安全监控系统
- sqlilabs less-11~12
- Sqlachemy common operations
- 既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?
- [repair version] imitating the template of I love watching movies website / template of ocean CMS film and television system
猜你喜欢

QT learning management system

原来程序员搞私活这么赚钱?真的太香了

【牛客网刷题系列 之 Verilog快速入门】~ 多功能数据处理器、求两个数的差值、使用generate…for语句简化代码、使用子模块实现三输入数的大小比较

2022年PMP项目管理考试敏捷知识点(6)

WebSocket(简单体验版)

App automation testing Kaiyuan platform appium runner

Use of Oracle database objects

Logic is a good thing

Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine

Summary of leetcode's dynamic programming 5
随机推荐
原来程序员搞私活这么赚钱?真的太香了
日志中打印统计信息的方案
Research Report on the development trend and competitive strategy of the global aviation leasing service industry
基于算力驱动、数据与功能协同的分布式动态(协同)渲染/功能运行时
30 Devops interview questions and answers
leetcode622. Design cycle queue (C language)
使用 Lambda 函数URL + CloudFront 实现S3镜像回源
sqlilabs less9
Force deduction solution summary 241- design priority for operation expression
Basic concepts of programming
App automation testing Kaiyuan platform appium runner
深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障
被裁三个月,面试到处碰壁,心态已经开始崩了
数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
算网融合赋能行业转型,移动云点亮数智未来新路标
Provincial election + noi Part IX game theory
2022-2-15 learning xiangniuke project - Section 4 business management
Research Report on the development trend and competitive strategy of the global axis measurement system industry
Use of Oracle database objects
sqlilabs less-8