java 随机字母数字生成算法
来源:互联网 发布:php仿qq聊天系统 编辑:程序博客网 时间:2024/05/22 00:41
package com.lcs.code;import java.io.File;import java.io.FileNotFoundException;import java.io.PrintWriter;import java.util.Map;import java.util.Random;import java.util.concurrent.ConcurrentHashMap;import org.junit.Test;/** * 随机码生成 * @author lcs * */public class RandomCodeUtil {public static void main(String[] args) {/*Map<String, Object> code = new ConcurrentHashMap<>();long start = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { code.put(randomStrAA(6), i); } long end = System.currentTimeMillis(); long time = end-start; System.out.println("生成时间:"+time); System.out.println(code.size());*/for (int i = 1; i < 100; i++) {//System.out.println(int_to_alphabet(i));}int_to_alphabet();}private static Random strGen = new Random();; private static Random numGen = new Random();; private static char[] numbersAndAA = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();; private static char[] numbersAndAa = ("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();; private static char[] numbers = ("0123456789").toCharArray();; @Testpublic static void int_to_alphabet(){try {File fp=new File("D:\\a.txt");Map<String, String> maps2 = randomStrAAMap(4, 1000000);//System.setOut(new PrintStream(new FileOutputStream("system_out.txt")));PrintWriter pfp;pfp = new PrintWriter(fp);pfp.print(maps2.keySet().toString());pfp.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}}/** * 产生N个随机字符串 * */ public static final Map<String,String> randomStrAAMap(int length,int N) { Map<String, String> map = new ConcurrentHashMap<String, String>();int i = 0;while (map.size()<=N) {i++;System.out.println("执行第"+i+"次"+"集合大小"+map.size());map.put(randomStrAA(length), i+"");}System.out.println("执行次数"+i);return map;} /** * 产生随机字符串 * */ public static final String randomStrAA(int length) { if (length < 1) { return null; } char[] randBuffer = new char[length]; for (int i = 0; i < randBuffer.length; i++) { randBuffer[i] = numbersAndAA[strGen.nextInt(35)]; } return new String(randBuffer); } /** * 产生随机字符串 * */ public static final String randomStrAa(int length) { if (length < 1) { return null; } char[] randBuffer = new char[length]; for (int i = 0; i < randBuffer.length; i++) { randBuffer[i] = numbersAndAa[strGen.nextInt(35)]; } return new String(randBuffer); } /** * 产生随机数值字符串 * */ public static final String randomNumStr(int length) { if (length < 1) { return null; } char[] randBuffer = new char[length]; for (int i = 0; i < randBuffer.length; i++) { randBuffer[i] = numbers[numGen.nextInt(9)]; } return new String(randBuffer); } }
0 0
- java 随机字母数字生成算法
- java生成随机数字和字母组合
- Java生成随机字母和数字
- java生成随机数字和字母组合
- java生成随机数字和字母组合
- java生成随机数字和字母组合
- java生成随机数字和字母组合
- java生成随机数字和字母组合
- java 生成随机数字或者字母
- java随机生成数字字母验证码
- Java随机生成数字和字母
- 随机生成数字字母
- 随机生成字母+数字
- java生成随机字母
- Java随机生成字母
- java生成随机字母
- Java基础之随机生成数字和字母
- java 随机生成字符串 (字母和数字)
- Tomcat启动时SecureRandom超级慢的问题
- HDU 1003 Max Sum
- 8. String to Integer (atoi)
- mysql基本操作
- Guava Cache的Ticker
- java 随机字母数字生成算法
- 14.6.7 Configuring the Number of Background InnoDB IO Threads 配置InnoDB IO Threads的数量
- CSDN停止更新啦,欢迎大家关注我的Github https://github.com/chenguolin
- PCBA电路板组装焊接的一般原则
- 获取用户名跟密码的servlet小案例
- MTK Camera 如何实现插值(转载)
- 大数相加与相乘算法实现
- PCB设计布局过程和规范
- 如何退出当前所有activity,重新进入loginActivity界面