Lucio Lelii 8 years ago
parent fb77e1f630
commit 751f4f4621

@ -347,28 +347,32 @@ public class SQLDatabaseWrangler implements DatabaseWrangler {
public static class RandomString {
private static final char[] symbols;
private static final char[] startingSymbols;
static {
StringBuilder tmp = new StringBuilder();
for (char ch = '0'; ch <= '9'; ++ch)
tmp.append(ch);
for (char ch = 'a'; ch <= 'z'; ++ch)
tmp.append(ch);
startingSymbols = tmp.toString().toCharArray();
for (char ch = '0'; ch <= '9'; ++ch)
tmp.append(ch);
symbols = tmp.toString().toCharArray();
}
private final int length;
private final Random random = new Random();
private final char[] buf;
public RandomString(int length) {
if (length < 1)
throw new IllegalArgumentException("length < 1: " + length);
buf = new char[length];
this.length = length;
}
public String nextString() {
for (int idx = 0; idx < buf.length; ++idx)
public synchronized String nextString() {
char[] buf = new char[this.length];
buf[0] = startingSymbols[random.nextInt(startingSymbols.length)];
for (int idx = 1; idx < buf.length; ++idx)
buf[idx] = symbols[random.nextInt(symbols.length)];
return new String(buf);
}

Loading…
Cancel
Save