当前位置:编程学习 > JAVA >>

[Java]生成32位随机字符ID

[java]
/** 
     * 生成32位编码 
     * @return string 
     */   
    public static String getUUID(){   
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");   
        return uuid;   
    }   
       
    /** 
     * 自定义规则生成32位编码 
     * @return string 
     */   
    public static String getUUIDByRules(String rules)   
    {   
      int rpoint = 0;   
        StringBuffer generateRandStr = new StringBuffer();   
        Random rand = new Random();   
        int length = 32;   
        for(int i=0;i<length;i++)   
        {   
            if(rules!=null){   
                rpoint = rules.length();   
                int randNum = rand.nextInt(rpoint);   
                generateRandStr.append(radStr.substring(randNum,randNum+1));   
            }   
        }   
        return generateRandStr+"";   
    }   

摘自 那年那月那天
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,