利用UUID 随机生成8位短号

//获得8位短号
public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
  "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8",
  "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
  "U", "V", "W", "X", "Y", "Z" };

public static String generateShortUuid() {
  StringBuffer shortBuffer = new StringBuffer();
  String uuid = UUID.randomUUID().toString().replace("-", "");
  for (int i = 0; i < 8; i++) {
    String str = uuid.substring(i * 4, i * 4 + 4);
    int x = Integer.parseInt(str, 16);
    shortBuffer.append(chars[x % 0x3E]);
  }
  return shortBuffer.toString();
}

时间: 2025-01-15 08:46:28

利用UUID 随机生成8位短号的相关文章

随机生成16位的16进制数

利用Python的uuid模块生成16位的16进制数 #!/usr/bin/env python3 # -*- coding: utf-8 -*- import uuid for i in range(100): res = str(uuid.uuid4()) res = res.replace('-', '') print(res[:16]) 随机生成100个16位的16进制数: e77ddca3bb474c9d fb96d68a32754500 2c5dc4347fcd43c0 b51bff

js随机生成4位验证码

方法一: /*随机生成4位验证码*/ /*step1:将所有字母,数字装入一个数组备用*/ var codes=[]; //数字:48-57;unicode编码 for(var i=48;i<57;codes.push(i),i++); /*console.log(codes);*/ //大写字母:65-90;unicode编码 for(var i=60;i<90;codes.push(i),i++); //小写字母:97-122;unicode编码 for(var i=97;i<122

随机生成32位字符串算法

随机生成32位字符串算法: function getRandom() { var arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D"

随机生成4位验证码,由用户输入并验证是否输入正确,如果输入错误就生成新的验证码让用户重新输入,最多输入5次

1 //四位随机验证码 2 Random ran=new Random(); 3 String str1 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXUZ"; 4 char [] a=new char[4]; 5 for(int i=0;i<4;i++) 6 { 7 a[i]=str1.charAt(ran.nextInt(62)); 8 } 9 10 StringBuilder rzm1= new

python操作redis之随机生成18位身份证号码

写一个随机生成身份证号的程序,输入多少条就产生多少个,?把产生完的数据写到redis里面,key用哈希类型?Xiaohei 410881198312031241 其中配置文件confsetting.py里的常量有: # 系统常量,包含: # LAST_NAME: 姓 # FIRST_NAME: 名 # STATE_CODE:全国大陆地区及编码 REDIS_IP = '172.16.2.163' RedisIp REDIS_PORT = 6379 REDIS_PASSWD = '222333' R

随机生成16位颜色

createRandomColor() { let color = Math.floor((Math.random() * 256 * 256 * 256)).toString(16) while (color.length < 6) {//随机生成的可能只有3-6位字符串 color += Math.floor((Math.random() * 16)).toString(16) } return color }

利用递归函数随机生成N个TXT文件

import random#导入随机模块def fileduoduo(n):    file_name = random.randint(000000, 999999)#文件名按六位数字随机生成    content = random.randint(000000000,999999999)    n+=1    if n <=50:#假定随机生成50个TXT文件        d = open("%s.txt" % file_name, 'w')#文件名        d.wr

随机生成60位同学成绩,并求他们的平均数,中位数,众数等

import randomimport numpy as np def random_int_list(start, stop, length): start, stop = (int(start), int(stop)) if start <= stop else (int(stop), int(start)) length = int(abs(length)) if length else 0 random_list = [] for i in range(length): random_l

java随机生成6位随机数 5位随机数 4位随机数

随机数,应用会相当广,验证数,订单号,流水号拼接. 下面是java随机数生成语句: 生成6位随机数(不会是5位或者7位,仅只有6位): System.out.println((int)((Math.random()*9+1)*100000)); 同理,生成5位随机数: System.out.println((int)((Math.random()*9+1)*10000)); 同理,生成4位随机数: System.out.println((int)((Math.random()*9+1)*1000