Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
53 lines (42 loc) · 1.48 KB

File metadata and controls

53 lines (42 loc) · 1.48 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package diffr.util;
import com.google.common.collect.Lists;
import javolution.text.Text;
import java.util.List;
import java.util.Random;
/**
* Utilities for generating random files.
*
* @author Jakub D Kozlowski
* @since 0.3
*/
public final class RandomFiles {
/**
* Gets a randomly generated file of this {@code fileLength} using this {@code seed} to initialise the random
* number generator.
*
* @param fileLength fileLength of the file to generate.
* @param seed initial seed.
*
* @return random file of this {@code fileLength}, generated from this {@code seed}.
*/
public static List<Text> getRandomFile(final long fileLength, final long seed) {
final List<Text> testFile = Lists.newArrayList();
final Random random = new Random(seed);
final char minChar = 33;
final int charRange = 127 - 33 + 1;
for (int i = 0; i < fileLength; i++) {
if (0 == random.nextInt(4) || 0 == testFile.size()) {
final StringBuilder b = new StringBuilder();
final int lineLength = random.nextInt(100) + 1;
for (int j = 0; j < lineLength; j++) {
b.append((char) (minChar + (random.nextInt(charRange))));
}
testFile.add(new Text(b.toString()));
}
else {
testFile.add(testFile.get(random.nextInt(testFile.size())));
}
}
return testFile;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.