生成8位随机大小写字母加数字随机数
生活随笔
收集整理的這篇文章主要介紹了
生成8位随机大小写字母加数字随机数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public static String getRundom(){
// 48-57 65-90 97-122
StringBuffer id=new StringBuffer();
Random random = new Random();
for (int i = 0; i < 8; i++) {
char s = 0;
int j=random.nextInt(3) % 4;
switch (j) {
case 0:
//隨機生成數字
s = (char) (random.nextInt(57) % (57 - 48 + 1) + 48);
break;
case 1:
//隨機生成大寫字母
s = (char) (random.nextInt(90) % (90 - 65 + 1) + 65);
break;
case 2:
//隨機生成小寫字母
s = (char) (random.nextInt(122) % (122 - 97 + 1) + 97);
break;
}
id.append(s);
}
return id.toString();
}
總結
以上是生活随笔為你收集整理的生成8位随机大小写字母加数字随机数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPhone 14 Pro Max上热搜
- 下一篇: 【译】颜色空间 REC.709 vs s