当前位置:网站首页>生成随机数(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;
}
}
边栏推荐
- 【修复版】仿我爱看电影网站模板/海洋CMS影视系统模板
- Fiori applications are shared through the enhancement of adaptation project
- 使用 Lambda 函数URL + CloudFront 实现S3镜像回源
- Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
- C 语言基础
- 用对场景,事半功倍!TDengine 的窗口查询功能及使用场景全介绍
- One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
- Use of Oracle database objects
- Halo effect - who says that those with light on their heads are heroes
- Effet halo - qui dit qu'il y a de la lumière sur la tête est un héros
猜你喜欢

既不是研发顶尖高手,也不是销售大牛,为何偏偏获得 2 万 RMB 的首个涛思文化奖?

One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse

建立自己的网站(21)

Logic is a good thing

Use of Oracle database objects

phpcms实现订单直接支付宝支付功能

Use lambda function URL + cloudfront to realize S3 image back to source

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

用栈实现队列、用队列实现栈(C语言_leetcode_232+225)

我们该如何保护自己的密码?
随机推荐
After being laid off for three months, the interview ran into a wall everywhere, and the mentality has begun to collapse
Leetcode(69)——x 的平方根
Provincial election + noi Part IX game theory
Sorting learning sorting
Research Report on the development trend and competitive strategy of the global axis measurement system industry
SWT / anr problem - how to open binder trace (bindertraces) when sending anr / SWT
Admire, Ali female program undercover more than 500 black production groups
深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障
Opencv interpolation mode
C 语言进阶
Details of appium key knowledge
队列的基本操作(C语言实现)
Journal MySQL
算网融合赋能行业转型,移动云点亮数智未来新路标
Play with grpc - communication between different programming languages
日志中打印统计信息的方案
643. Maximum average number of subarrays I
Research Report on the development trend and competitive strategy of the global ultrasonic scalpel system industry
光环效应——谁说头上有光的就算英雄
【NLP】预训练模型——GPT1