mirror of
https://e.coding.net/circlecloud/AuthMe.git
synced 2025-11-26 21:46:23 +00:00
39 lines
804 B
Java
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);
|
|
}
|
|
|
|
}
|