diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml
index 69e8e5f..538981b 100644
--- a/luoo_user/pom.xml
+++ b/luoo_user/pom.xml
@@ -72,11 +72,6 @@
lombok
true
-
- com.apifan.common
- common-random
- 1.0.21
-
com.h2database
h2
diff --git a/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java b/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java
index 5d2b08c..1233417 100644
--- a/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java
+++ b/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java
@@ -1,23 +1,21 @@
package com.luoo.user.util;
-import com.apifan.common.random.RandomSource;
+import java.util.Random;
public class NickNameUtil {
- /**
- * 最终名为: 雀乐/游客-XXXX-XXXX,经分析用户量1000万时,重名率为0.000001%
- * eg:
- * 雀乐-冬力一柏.朋长
- * 雀乐-莹玲书蕊&贤秋
- * 雀乐-博应杨-沛道
- * 雀乐-石济$丁然自钧
- */
- private static String[] SPECIAL_CHARACTER = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|",
- ".", "<", ">" };
+ private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+
+ private static String generateRandomString(int length) {
+ StringBuilder sb = new StringBuilder(length);
+ Random random = new Random();
+ for (int i = 0; i < length; i++) {
+ int index = random.nextInt(CHARACTERS.length());
+ sb.append(CHARACTERS.charAt(index));
+ }
+ return sb.toString();
+ }
public static String getRandomNickName() {
- int index = RandomSource.numberSource().randomInt(0, SPECIAL_CHARACTER.length);
- String character = SPECIAL_CHARACTER[index];
- return RandomSource.personInfoSource().randomChineseNickName(4) + character
- + RandomSource.personInfoSource().randomChineseNickName(4);
+ return generateRandomString(9);
}
}
diff --git a/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java b/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java
index 2fdfc41..ce22144 100644
--- a/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java
+++ b/luoo_user/src/test/java/com/luoo/user/util/NickNameUtilTest.java
@@ -1,47 +1,18 @@
package com.luoo.user.util;
-import java.util.Arrays;
-import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Test;
-import org.springframework.util.StopWatch;
-
-import com.apifan.common.random.RandomSource;
-import com.apifan.common.random.entity.Poem;
public class NickNameUtilTest {
- int size = 4;
-
- String[] content = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|", ".", "<", ">" };
-
@Test
public void test() {
- int total = 100000;
+ int total = 1000000;
System.out.println("total: " + total);
- StopWatch sw = new StopWatch();
- sw.start();
- IntStream.range(0, total).parallel().mapToObj(j -> getRandomNickName()).limit(100).forEach(System.out::println);
- for (int i = 4; i < 5; i++) {
- size = i;
- long distinctNickName = IntStream.range(0, total).parallel().mapToObj(j -> getRandomNickName()).distinct()
- .count();
- System.out.println("length: " + i + " distinctCount: " + distinctNickName);
- }
- sw.stop();
- System.out.println(sw.prettyPrint());
-
- Poem poem=RandomSource.languageSource().randomTangPoem();
- System.out.println(poem.getAuthor());
- String content=Arrays.stream(poem.getContent()).collect(Collectors.joining("\r\n"));
- System.out.println(content);
+ IntStream.range(0, total).parallel().mapToObj(j -> NickNameUtil.getRandomNickName()).limit(10)
+ .forEach(System.out::println);
+ long distinctNickName = IntStream.range(0, total).parallel().mapToObj(j -> NickNameUtil.getRandomNickName())
+ .distinct().count();
+ System.out.println("length: " + 9 + " distinctCount: " + distinctNickName);
}
-
- public String getRandomNickName() {
- int index = RandomSource.numberSource().randomInt(0, content.length);
- String character = content[index];
- return "雀乐-" + RandomSource.personInfoSource().randomChineseNickName(4) + character
- + RandomSource.personInfoSource().randomChineseNickName(4);
- }
-
}