短視訊直播系統,Java生成固定長度的隨機字串
阿新 • • 發佈:2021-08-04
短視訊直播系統,Java生成固定長度的隨機字串實現的相關程式碼
```cpp public class RandomStringUtil { public static ArrayList<String> strList = new ArrayList<String>(); public static Random random = new Random(); static { init(); } public static String generate32RandomStr() { return generateRandomStr(32); } publicstatic String generateRandomStr(int length) { StringBuffer sb = new StringBuffer(); for(int i = 0; i < length; i++) { int size = strList.size(); String randomStr = strList.get(random.nextInt(size)); sb.append(randomStr); } return sb.toString(); } public static void init() { int begin = 97; //生成小寫字母,並加入集合for(int i = begin; i < begin + 26; i++) { strList.add((char)i + ""); } //生成大寫字母,並加入集合 begin = 65; for(int i = begin; i < begin + 26; i++) { strList.add((char)i + ""); } //將0-9的數字加入集合 for(int i = 0; i < 10; i++) { strList.add(i + ""); } } } ```
以上就是短視訊直播系統,Java生成固定長度的隨機字串實現的相關程式碼, 更多內容歡迎關注之後的文章