生成短8位唯一字符ID

項目需要用到8位唯一字符,UUID是32位,不能滿足需求。

用到的類:

org.apache.commons.lang.RandomStringUtils

相關方法:

random(int count);
randomAscii(int count);
randomAlphabetic(int count);
randomAlphanumeric(int count);
randomNumeric(int count);
random(int count, boolean letters, boolean numbers);
random(int count, int start, int end, boolean letters, boolean numbers);
random(int count, int start, int end, boolean letters, boolean numbers, char[] chars);
random(int count, String chars);
random(int count, char[] chars);

我測試了

random(int count);
randomAlphabetic(int count);
randomNumeric(int count);

這幾個方法,在百萬級數據量時,均有重複,且重複個數不低。測試

randomAlphanumeric(int count)

方法後,同樣數據量沒有重複,然後就做了個偶然性測試,發現生成1000次百萬級數據量的時候,有3次重複,基本可用。

貼上測試圖:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章