当前位置:网站首页>生成随机数(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;
}
}
边栏推荐
- Research Report on the development trend and competitive strategy of the global camera filter bracket industry
- 【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
- 程序设计的基本概念
- sqlilabs less10
- 111. Minimum depth of binary tree
- Sorting learning sorting
- sqlilabs less-11~12
- sqlilabs less9
- Opencv mat class
- What problems should be considered for outdoor LED display?
猜你喜欢

Details of appium key knowledge

【IoT毕设.下】STM32+机智云AIoT+实验室安全监控系统
![[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system](/img/b2/e8f81ecda6f5f4fc65501aaf9f13cf.gif)
[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system

TDengine 连接器上线 Google Data Studio 应用商店

Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server

队列的基本操作(C语言实现)

111. Minimum depth of binary tree

QT community management system

Websocket (simple experience version)

QT learning management system
随机推荐
Six years of technology iteration, challenges and exploration of Alibaba's globalization and compliance
Research Report on the development trend and competitive strategy of the global powder filling machine industry
[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system
C language course design topic
MySQL日志
How will the surging tide of digitalization overturn the future?
sqlilabs less13
如何看待国企纷纷卸载微软Office改用金山WPS?
What "hard core innovations" does Intel have in the first half of 2022? Just look at this picture!
C 语言基础
用栈实现队列、用队列实现栈(C语言_leetcode_232+225)
SWT/ANR问题--如何捕获性能的trace
Research Report on the development trend and competitive strategy of the global ultrasonic scalpel system industry
Tdengine connector goes online Google Data Studio app store
光環效應——誰說頭上有光的就算英雄
券商万1免5证券开户是合理安全的吗,怎么讲
How to pass array parameters in get request
Research Report on the development trend and competitive strategy of the global display filter industry
队列的基本操作(C语言实现)
【R语言数据科学】:机器学习常见评估指标