1. 程式人生 > 其它 >短視訊直播系統,Java生成固定長度的隨機字串

短視訊直播系統,Java生成固定長度的隨機字串

短視訊直播系統,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);
}

public
static 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生成固定長度的隨機字串實現的相關程式碼, 更多內容歡迎關注之後的文章