import java.util.Random; import java.util.UUID; public class UUIDUtils { public static String getUUID(){ return UUID.randomUUID().toString().replace("-", ""); } //随机产生数字字母 public static String getStringRandom() { String val = ""; Random random = new Random(); //参数length,表示生成100位随机数 for(int i = 0; i < 100; i++) { String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; //输出字母还是数字 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("随机产生100位数字字母:"+val); return val; } public static void main(String[] args) { System.out.println("格式前的UUID:" + UUID.randomUUID().toString()); System.out.println("格式化后的UUID:" + getUUID()); getStringRandom(); } }
展示:
1. https://www.cnblogs.com/aGboke/p/5488327.html
2. https://blog.csdn.net/cndmss/article/details/51996876