UUID+随机数
import java.util.Random;
import java.util.UUID;public class UUIDUtils {public static String getUUID(){return UUID.randomUUID().toString().replace("-", "");}//隨機(jī)產(chǎn)生數(shù)字字母public static String getStringRandom() { String val = ""; Random random = new Random(); //參數(shù)length,表示生成100位隨機(jī)數(shù) for(int i = 0; i < 100; i++) { String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; //輸出字母還是數(shù)字 if( "char".equalsIgnoreCase(charOrNum) ) { //輸出是大寫字母還是小寫字母 int temp = random.nextInt(2) % 2 == 0 ? 65 : 97; val += (char)(random.nextInt(26) + temp); } else if( "num".equalsIgnoreCase(charOrNum) ) { val += String.valueOf(random.nextInt(10)); } } System.out.println("隨機(jī)產(chǎn)生100位數(shù)字字母:"+val);return val; } public static void main(String[] args) {System.out.println("格式前的UUID:" + UUID.randomUUID().toString());System.out.println("格式化后的UUID:" + getUUID());getStringRandom();}
}
展示:
鏈接:Java隨機(jī)生成定長(zhǎng)純數(shù)字或數(shù)字字母混合數(shù)
? 1. https://www.cnblogs.com/aGboke/p/5488327.html
2. https://blog.csdn.net/cndmss/article/details/51996876
?
轉(zhuǎn)載于:https://www.cnblogs.com/Steven5007/p/10021567.html
總結(jié)
- 上一篇: docker 部署mysql服务之后,执
- 下一篇: Alpha 冲刺 —— 十分之八