!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; | package cn.lili.common.utils; | ||||||
| 
 | 
 | ||||||
| import java.util.Random; |  | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
|  | import java.util.concurrent.ThreadLocalRandom; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * 通用工具 |  * 通用工具 | ||||||
| @ -9,6 +9,8 @@ import java.util.UUID; | |||||||
|  */ |  */ | ||||||
| public class CommonUtil { | public class CommonUtil { | ||||||
| 
 | 
 | ||||||
|  |     public static final String BASE_NUMBER = "0123456789"; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * 以UUID重命名 |      * 以UUID重命名 | ||||||
|      * @param fileName 文件名称 |      * @param fileName 文件名称 | ||||||
| @ -24,12 +26,12 @@ public class CommonUtil { | |||||||
|      * 随机6位数生成 |      * 随机6位数生成 | ||||||
|      */ |      */ | ||||||
|     public static String getRandomNum() { |     public static String getRandomNum() { | ||||||
| 
 |         StringBuilder sb = new StringBuilder(6); | ||||||
|         Random random = new Random(); |         for (int i = 0; i < 6; i++) { | ||||||
|         int num = random.nextInt(999999); |             int num = ThreadLocalRandom.current().nextInt(BASE_NUMBER.length()); | ||||||
|         //不足六位前面补0 |             sb.append(BASE_NUMBER.charAt(num)); | ||||||
|         String str = String.format("%06d", num); |         } | ||||||
|         return str; |         return sb.toString(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 chopper711
						chopper711