27
28
public stringGenerator(alphabet: string): IGenerator<string> {
30
>
next: () => {
31
>
const characterIndex = this.nextIntRange(0, alphabet.length);
32
>
return alphabet.charAt(characterIndex);
33
>
}
34
>
};
35
>
}
36
37
public abstract nextIntRange(start: number, endExclusive: number): number;
38
39
public nextString(length: number, alphabet = this.stringGenerator(Random.basicAlphabet)): string {
41
>
for (let i = 0; i < length; i++) {
42
>
randomText += alphabet.next();
43
>
}
44
>
return randomText;
45
>
}
46
47
public nextMultiLineString(lineCount: number, lineLengthRange: OffsetRange, alphabet = this.stringGenerator(Random.basicAlphabet)): string {
49
>
for (let i = 0; i < lineCount; i++) {
50
>
const lineLength = this.nextIntRange(lineLengthRange.start, lineLengthRange.endExclusive);
51
>
lines.push(this.nextString(lineLength, alphabet));
52
>
}
53
>
return lines.join('\n');
54
>
}
55
56
public nextConsecutiveOffsets(range: OffsetRange, count: number): number[] {
57
>
const offsets = OffsetRange.ofLength(count).map(() => this.nextIntRange(range.start, range.endExclusive));
random.ts
58
>
offsets.sort(numberComparator);
59
>
return offsets;
60
>
}
61
62
public nextConsecutivePositions(source: AbstractText, count: number): Position[] {
63
>
const t = new PositionOffsetTransformer(source.getValue());
random.ts
64
>
const offsets = this.nextConsecutiveOffsets(new OffsetRange(0, t.text.length), count);
65
>
return offsets.map(offset => t.getPosition(offset));
66
>
}
67
68
public nextRange(source: AbstractText): Range {