1.update random nickName generator

main
Gary 9 months ago
parent d6de6a01cc
commit 3e016bd97f

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

@ -1,23 +1,21 @@
package com.luoo.user.util;
import com.apifan.common.random.RandomSource;
import java.util.Random;
public class NickNameUtil {
/**
* /-XXXX-XXXX10000.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);
}
}

@ -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);
}
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);
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);
}
}

Loading…
Cancel
Save