1. 程式人生 > >UUID+隨機數

UUID+隨機數

eof pla println static void 小寫 gets .net sdn

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(); } }

展示:

技術分享圖片

鏈接:Java隨機生成定長純數字或數字字母混合數

  1. https://www.cnblogs.com/aGboke/p/5488327.html

   2. https://blog.csdn.net/cndmss/article/details/51996876

UUID+隨機數