forked from IHoffman5214/Calendar-Event-File-Generator
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomString.java
More file actions
Latest commit
32 lines (25 loc) · 817 Bytes
/
Copy pathRandomString.java
File metadata and controls
32 lines (25 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importjava.util.Random;
//http://stackoverflow.com/questions/41107/how-to-generate-a-random-alpha-numeric-string
publicclassRandomString {
privatestaticfinalchar[] symbols;
static {
StringBuildertmp = newStringBuilder();
for (charch = '0'; ch <= '9'; ++ch)
tmp.append(ch);
for (charch = 'a'; ch <= 'z'; ++ch)
tmp.append(ch);
symbols = tmp.toString().toCharArray();
}
privatefinalRandomrandom = newRandom();
privatefinalchar[] buf;
publicRandomString(intlength) {
if (length < 1)
thrownewIllegalArgumentException("length < 1: " + length);
buf = newchar[length];
}
publicStringnextString() {
for (intidx = 0; idx < buf.length; ++idx)
buf[idx] = symbols[random.nextInt(symbols.length)];
returnnewString(buf);
}
}