[Java]生成32位隨機字符ID – JAVA編程語言程序開發技術文章

[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+"";   
    }   

摘自 那年那月那天

發佈留言