01: package org.slf4j.migrator.helper;
02:
03: import java.util.Random;
04:
05: public class RandomHelper {
06:
07: private Random random = new Random(100);
08: final char folderSeparator;
09:
10: RandomHelper(char folderSeparator) {
11: this .folderSeparator = folderSeparator;
12: }
13:
14: private String randomString(int len) {
15: StringBuffer buf = new StringBuffer();
16: for (int i = 0; i < len; i++) {
17: int offset = random.nextInt(26);
18: char c = (char) ('a' + offset);
19: buf.append(c);
20: }
21: return buf.toString();
22: }
23:
24: int nextInt(int n) {
25: return random.nextInt(n);
26: }
27:
28: String buildRandomFileName(int averageNodeLength, int totalLength) {
29: StringBuffer buf = new StringBuffer();
30: int MAX_NODE_LENGTH = averageNodeLength * 2;
31: while (buf.length() < totalLength) {
32: int remaining = totalLength - buf.length();
33: int currentNodeLength;
34: if (remaining > MAX_NODE_LENGTH) {
35: currentNodeLength = random.nextInt(MAX_NODE_LENGTH) + 1;
36: buf.append(randomString(currentNodeLength));
37: buf.append('/');
38: } else {
39: currentNodeLength = remaining;
40: buf.append(randomString(currentNodeLength));
41: }
42: }
43: return buf.toString();
44: }
45:
46: }
|