2016-10-18 32 views
0

在我的spring mvc應用程序中,我已經使用下面的代碼來生成用於激活應用程序的串行密鑰。密鑰由12個帶有alpha數字的字符組成。在Spring中使用RandomStringUtils的密鑰生成mvc

RandomStringUtils.random(12, true, true).toUpperCase().toString() 

是生成唯一使用密鑰RandomStringUtils會發生什麼,它會達到它的極限這個正確的方法。

+1

我不知道該功能的具體細節,但調用'toUpperCase'弦上看起來不正確的,因爲它一倍的頻率字母與數字相比較。 – Henry

+0

客戶端需要大寫鍵,這就是爲什麼toUpperCase – boycod3

+0

在原始字符串'a'中,'A'和'1'將以相同的頻率出現。如果您現在將'a'映射到'A',您將擁有比'1'多一倍的'A'。 – Henry

回答

0

爲什麼不使用特別符合您的要求的方法。

公共靜態字符串randomAlphanumeric(詮釋計數)

Creates a random string whose length is the number of characters specified. 

Characters will be chosen from the set of alpha-numeric characters. 

Parameters: 
    count - the length of random string to create 
Returns: 
    the random string 
+0

請分享代碼 – boycod3