1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2025-11-26 21:46:23 +00:00
Files
AuthMe/src/main/java/fr/xephi/authme/security/RandomString.java
502647092 a1176afa15 init project...
Signed-off-by: 502647092 <jtb1@163.com>
2015-10-12 15:26:15 +08:00

39 lines
804 B
Java

package fr.xephi.authme.security;
import java.util.Calendar;
import java.util.Random;
/**
*
* @author Xephi59
*/
public class RandomString {
private static final char[] chars = new char[36];
private final char[] buf;
private final Random random = new Random();
public RandomString(int length) {
if (length < 1)
throw new IllegalArgumentException("length < 1: " + length);
buf = new char[length];
random.setSeed(Calendar.getInstance().getTimeInMillis());
}
static {
for (int idx = 0; idx < 10; ++idx)
chars[idx] = (char) ('0' + idx);
for (int idx = 10; idx < 36; ++idx)
chars[idx] = (char) ('a' + idx - 10);
}
public String nextString() {
for (int idx = 0; idx < buf.length; ++idx)
buf[idx] = chars[random.nextInt(chars.length)];
return new String(buf);
}
}