搜索
简帛阁>技术文章>java实现随机生成UUID

java实现随机生成UUID

java实现随机生成UUID

public class IDGenerator {
   
  private static long num=0; 
   
  /**
   * 随机生成UUID
   * @return
   */
  public static synchronized String getUUID(){
    UUID uuid=UUID.randomUUID();
    String str = uuid.toString(); 
    String uuidStr=str.replace("-", "");
    return uuidStr;
  }
  /**
   * 根据字符串生成固定UUID
   * @param name
   * @return
   */
  public static synchronized String getUUID(String name){
    UUID uuid=UUID.nameUUIDFromBytes(name.getBytes());
    String str = uuid.toString(); 
    String uuidStr=str.replace("-", "");
    return uuidStr;
  }
  /**
   * 根据日期生成长整型id
   * @param args
   */
  public static synchronized long getLongId(){
    String date=DateUtil.getDate2FormatString(new Date(), "yyyyMMddHHmmssS");
    System.out.println("原始id="+date);
    if(num>=99) num=0l;
    ++num;
    if(num<10) {
      date=date+00+num;
    }else{
      date+=num;
    }
    return Long.valueOf(date);
  }
  
}

以上所述就是本文的全部内容了,希望大家能够喜欢。

java实现随机生成UUIDpublicclassIDGenerator{privatestaticlongnum0;/***随机生成UUID*@return*/publicstaticsynchr
GUID释义GUID是一个128位长的数字,一般用16进制表示。算法的核心思想是结合机器的网卡、当地时间、一个随机数来生成GUID。从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保
UID含义是通用唯一识别码(UniversallyUniqueIdentifier),这是一个软件建构的标准,也是被开源软件基金会(OpenSoftwareFoundation,OSF)的组织在分布式
UUID含义是通用唯一识别码(UniversallyUniqueIdentifier),这是一个软件建构的标准,也是被开源软件基金会(OpenSoftwareFoundation,OSF)的组织在分布
/***生成随机uuid*/exportfunctionuuid(){return'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'replace(/[xy]/g,function(
functionguid(){functionS4(){return(((1+Mathrandom())*0x10000)|0)toString(16)substring(1);}return(S4(
java通过jdk自带的UUID生成32位的随机串privatestaticStringgenerate_UUID(){UUIDuuidUUIDrandomUUID();Stringstruuid
importjavautilUUID;publicclassMainProcess{publicstaticvoidmain(String[]args){UUIDuuidUUIDrandomUUID(
1UUID简介UUID含义是通用唯一识别码(UniversallyUniqueIdentifier),这是一个软件建构的标准。也是被开源软件基金会(OpenSoftwareFoundation,OSF
shell生成随机mac[root@localhostimages]echo08:00:27:$(opensslrandhex3|sed's/\(\)/\1:/g;s/$//')08:00:27:40