!142 优化CommonUtil.getRandomNum() 提升随机数性能。 from @原批王
Merge pull request !142 from 原批王/master
This commit is contained in:
		
						commit
						07ce947f78
					
				| @ -1,7 +1,7 @@ | ||||
| package cn.lili.common.utils; | ||||
| 
 | ||||
| import java.util.Random; | ||||
| import java.util.UUID; | ||||
| import java.util.concurrent.ThreadLocalRandom; | ||||
| 
 | ||||
| /** | ||||
|  * 通用工具 | ||||
| @ -9,6 +9,8 @@ import java.util.UUID; | ||||
|  */ | ||||
| public class CommonUtil { | ||||
| 
 | ||||
|     public static final String BASE_NUMBER = "0123456789"; | ||||
| 
 | ||||
|     /** | ||||
|      * 以UUID重命名 | ||||
|      * @param fileName 文件名称 | ||||
| @ -24,12 +26,12 @@ public class CommonUtil { | ||||
|      * 随机6位数生成 | ||||
|      */ | ||||
|     public static String getRandomNum() { | ||||
| 
 | ||||
|         Random random = new Random(); | ||||
|         int num = random.nextInt(999999); | ||||
|         //不足六位前面补0 | ||||
|         String str = String.format("%06d", num); | ||||
|         return str; | ||||
|         StringBuilder sb = new StringBuilder(6); | ||||
|         for (int i = 0; i < 6; i++) { | ||||
|             int num = ThreadLocalRandom.current().nextInt(BASE_NUMBER.length()); | ||||
|             sb.append(BASE_NUMBER.charAt(num)); | ||||
|         } | ||||
|         return sb.toString(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 chopper711
						chopper711