1,生成UUID

package com.jeeplus.common.utils;

import java.util.UUID;

/**
* 生成唯一的UUID
*
* @author songyan
*
*/
public class UUIDUtils { /**
* 得到32位的uuid
*
* @return
*/
public static String getUUID32() {
return UUID.randomUUID().toString().replace("-", "").toLowerCase();
} /**
* 得到指定数量的UUID,以数组的形式返回
*
* @param num
* @return
*/
public static String[] getUUID(int num) {
if (num <= 0)
return null;
String[] uuidArr = new String[num];
for (int i = 0; i < uuidArr.length; i++) {
uuidArr[i] = getUUID32();
}
return uuidArr;
} 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" }; /**
* 生成8位UUId
*
* @return
*/
public static String generateUuid8() {
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(); } }

生成随机位数的UUID的更多相关文章

  1. 生成随机字符串(UUID方法)

    这是另一种用UUID生成随机字符串的方法. public class RandomGenerator{ private int length; public void setLength(int le ...

  2. php生成随机产生六位数密码的代码

    php生成随机产生六位数密码的代码,供大家学习参考.本文转自:http://www.jbxue.com/article/6199.html php生成随机产生六位数密码的代码,供大家学习参考. 复制代 ...

  3. PHP随机生成要求位数个字符(大小写字母+数字)

    php随机生成要求位数个字符 /** * 随机生成要求位数个字符 * @param length 规定几位字符 */ function getRandChar($length){ $str = nul ...

  4. python随机生成6位数验证码

    #随机生成6位数验证码 import randomcode = []for i in range(6):    if i == str(random.randint(1,5)):        cod ...

  5. java生成随机六位数的验证码&随机生成十位数ValidCode码,用于邮件的验证&检查是不是符合为合法的中国的手机号码

    package com.demo.test1; import java.security.NoSuchAlgorithmException; import java.security.SecureRa ...

  6. python3 随机生成6位数的验证码

    python3 随机生成6位数的验证码 要求是数字:0~9 及大小写字母. #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung ...

  7. 生成随机uuid

      /**  * 生成随机uuid  */ export function uuid() {   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.repla ...

  8. 生成随机id对比

    生成随机id 最近公司的项目游戏生成的随机不重复id,重复概率有点大, 代码如下: private static int id = 0; public static int serverID = 0; ...

  9. .net生成随机字符串

    生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...

随机推荐

  1. 转:极小极大搜索方法、负值最大算法和Alpha-Beta搜索方法

    转自:极小极大搜索方法.负值最大算法和Alpha-Beta搜索方法 1. 极小极大搜索方法    一般应用在博弈搜索中,比如:围棋,五子棋,象棋等.结果有三种可能:胜利.失败和平局.暴力搜索,如果想通 ...

  2. Nginx 默认配置解析

    # For more information on configuration, see: # * Official English Documentation: http://nginx.org/e ...

  3. 图论:Gale-Shapley算法

    Gale-Shapley算法又叫做延迟认可算法,它可以解决这么一个问题 一共有N位男士和N位女士 每位男士对每位女士都有一个好感度,让他们结合成为N对夫妻,要求男士优先表白,最后问结合情况 第一轮,每 ...

  4. [洛谷P1040] 加分二叉树

    洛谷题目链接:加分二叉树 题目描述 设一个n个节点的二叉树tree的中序遍历为(1,2,3,-,n),其中数字1,2,3,-,n为节点编号.每个节点都有一个分数(均为正整数),记第i个节点的分数为di ...

  5. c++对拍实现

    直接上代码吧. #include<bits/stdc++.h> using namespace std; int main(){ while(1){ system("./cute ...

  6. 【BZOJ】1799: [Ahoi2009]self 同类分布

    [题意]给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数.1 ≤ a ≤ b ≤ 10^18 [算法]数位DP [题解] 感觉这种方法很暴力啊. 枚举数位和1~162(不能枚举0,不然会模 ...

  7. bzoj 1042 DP+容斥原理

    我们可以先DP预处理出W[I]代表买I的东西,每种钞票的个数 不做限制的方案数,那么对于每一组数据的限制,我们可以知道 W[S-C[I]*(D[I]+1)]C为面值,D为数量,这个代表第I种钞票一定 ...

  8. Chrome浏览器跨域插件

    Moesif Origin & CORS Changer 这个插件允许发送跨域请求,重写Request Origin 和 CORS headers. 解决Debug Javascript时候出 ...

  9. glib windows下编译

    记录的比较粗糙,但是绝对可行的 一些小的瑕疵以后再解决吧 (android版本的过几天再贴,移植到android已经通过) msys+mingw包下载: http://sourceforge.net/ ...

  10. Shell中的while循环【转】

    转自:http://blog.chinaunix.net/uid-25880122-id-2901409.html while循环的格式   while expression do command c ...