1.update random nickName generator

main
Gary 9 months ago
parent d6de6a01cc
commit 3e016bd97f

@ -72,11 +72,6 @@
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>com.apifan.common</groupId>
<artifactId>common-random</artifactId>
<version>1.0.21</version>
</dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>

@ -1,23 +1,21 @@
package com.luoo.user.util; package com.luoo.user.util;
import com.apifan.common.random.RandomSource; import java.util.Random;
public class NickNameUtil { public class NickNameUtil {
/** private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
* /-XXXX-XXXX10000.000001%
* eg: 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));
private static String[] SPECIAL_CHARACTER = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|", }
".", "<", ">" }; return sb.toString();
}
public static String getRandomNickName() { public static String getRandomNickName() {
int index = RandomSource.numberSource().randomInt(0, SPECIAL_CHARACTER.length); return generateRandomString(9);
String character = SPECIAL_CHARACTER[index];
return RandomSource.personInfoSource().randomChineseNickName(4) + character
+ RandomSource.personInfoSource().randomChineseNickName(4);
} }
} }

@ -1,47 +1,18 @@
package com.luoo.user.util; package com.luoo.user.util;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import org.junit.Test; 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 { public class NickNameUtilTest {
int size = 4;
String[] content = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|", ".", "<", ">" };
@Test @Test
public void test() { public void test() {
int total = 100000; int total = 1000000;
System.out.println("total: " + total); System.out.println("total: " + total);
StopWatch sw = new StopWatch(); IntStream.range(0, total).parallel().mapToObj(j -> NickNameUtil.getRandomNickName()).limit(10)
sw.start(); .forEach(System.out::println);
IntStream.range(0, total).parallel().mapToObj(j -> getRandomNickName()).limit(100).forEach(System.out::println); long distinctNickName = IntStream.range(0, total).parallel().mapToObj(j -> NickNameUtil.getRandomNickName())
for (int i = 4; i < 5; i++) { .distinct().count();
size = i; System.out.println("length: " + 9 + " distinctCount: " + distinctNickName);
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);
} }
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);
}
} }

Loading…
Cancel
Save