随机数代码优化

master
星期八 3 years ago
parent bc512abc0b
commit 61d69e4b5f
  1. 6
      panda-code/src/main/java/org/panda/code/uitl/StringUtil.java

@ -71,11 +71,11 @@ public class StringUtil {
public static String randomString(int length){ public static String randomString(int length){
StringBuffer randomString=new StringBuffer(); StringBuffer randomString=new StringBuffer();
while (length>0){ while (length>0){
Random random=new Random(); ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
int ran=random.nextInt(3); int ran=threadLocalRandom.nextInt(3);
switch (ran){ switch (ran){
case 0: case 0:
randomString.append(random.nextInt(10)); randomString.append(threadLocalRandom.nextInt(10));
break; break;
case 1: case 1:
randomString.append(randomLowerCase()); randomString.append(randomLowerCase());

Loading…
Cancel
Save