random.ts ×18

Frontier kind: Code frontier

unlabeled · c_c596f0e389f0

2282 tests · 6429 LOC · 38 files · introduces 0 tests · 74 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
18 ranges74 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1069 ranges6429 lines · 38 files · Browse complete extent
All tests (intent)
2282 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 74 introduced LOC across 18 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/test/common/core/random.ts 74 introduced LOC · 18 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- random.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { numberComparator } from '../../../../base/common/arrays.js';
7 > import { BugIndicatingError } from '../../../../base/common/errors.js';
8 > import { StringEdit, StringReplacement } from '../../../common/core/edits/stringEdit.js';
9 > import { OffsetRange } from '../../../common/core/ranges/offsetRange.js';
10 > import { Position } from '../../../common/core/position.js';
11 > import { PositionOffsetTransformer } from '../../../common/core/text/positionToOffset.js';
12 > import { Range } from '../../../common/core/range.js';
13 > import { TextReplacement, TextEdit } from '../../../common/core/edits/textEdit.js';
14 > import { AbstractText } from '../../../common/core/text/abstractText.js';
15 >
16 > export abstract class Random {
17 > public static readonly alphabetSmallLowercase = 'abcdefgh';
18 > public static readonly alphabetSmallUppercase = 'ABCDEFGH';
19 > public static readonly alphabetLowercase = 'abcdefghijklmnopqrstuvwxyz';
20 > public static readonly alphabetUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
21 > public static readonly basicAlphabet: string = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
22 > public static readonly basicAlphabetMultiline: string = ' \n\n\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
23 >
24 > public static create(seed: number): Random {
25 return new MersenneTwister(seed);
26 }
27 > random.ts
28 > public stringGenerator(alphabet: string): IGenerator<string> {
29 return {
30 next: () => {
34 };
35 }
36 > random.ts
37 > public abstract nextIntRange(start: number, endExclusive: number): number;
38 >
39 > public nextString(length: number, alphabet = this.stringGenerator(Random.basicAlphabet)): string {
40 let randomText: string = '';
41 for (let i = 0; i < length; i++) {
44 return randomText;
45 }
46 > random.ts
47 > public nextMultiLineString(lineCount: number, lineLengthRange: OffsetRange, alphabet = this.stringGenerator(Random.basicAlphabet)): string {
48 const lines: string[] = [];
49 for (let i = 0; i < lineCount; i++) {
53 return lines.join('\n');
54 }
55 > random.ts
56 > public nextConsecutiveOffsets(range: OffsetRange, count: number): number[] {
57 const offsets = OffsetRange.ofLength(count).map(() => this.nextIntRange(range.start, range.endExclusive));
58 offsets.sort(numberComparator);
59 return offsets;
60 }
61 > random.ts
62 > public nextConsecutivePositions(source: AbstractText, count: number): Position[] {
63 const t = new PositionOffsetTransformer(source.getValue());
64 const offsets = this.nextConsecutiveOffsets(new OffsetRange(0, t.text.length), count);
65 return offsets.map(offset => t.getPosition(offset));
66 }
67 > random.ts
68 > public nextRange(source: AbstractText): Range {
69 const [start, end] = this.nextConsecutivePositions(source, 2);
70 return Range.fromPositions(start, end);
71 }
72 > random.ts
73 > public nextTextEdit(target: AbstractText, singleTextEditCount: number): TextEdit {
74 const singleTextEdits: TextReplacement[] = [];
75
85 return new TextEdit(singleTextEdits).normalize();
86 }
87 > random.ts
88 > public nextStringEdit(target: string, singleTextEditCount: number, newTextAlphabet = Random.basicAlphabetMultiline): StringEdit {
89 const singleTextEdits: StringReplacement[] = [];
90
103 return new StringEdit(singleTextEdits).normalize();
104 }
105 > random.ts
106 > public nextSingleStringEdit(target: string, newTextAlphabet = Random.basicAlphabetMultiline): StringReplacement {
107 const edit = this.nextStringEdit(target, 1, newTextAlphabet);
108 return edit.replacements[0];
109 }
110 > random.ts
111 > /**
112 > * Fills the given array with random data.
113 > */
114 > public nextRandomValues(data: Uint8Array): void {
115 for (let i = 0; i < data.length; i++) {
116 data[i] = this.nextIntRange(0, 256);
117 }
118 }
119 > random.ts
120 > private _hex: string[] | undefined;
121 > private _data: Uint8Array | undefined;
122 >
123 > public nextUuid(): string {
124 if (!this._data) {
125 this._data = new Uint8Array(16);
162 return result;
163 }
164 > } random.ts
165 >
166 > export function sequenceGenerator<T>(sequence: T[]): IGenerator<T> {
167 let index = 0;
168 return {
177 };
178 }
179 > random.ts
180 > export interface IGenerator<T> {
181 > next(): T;
182 > }
183 >
184 > class MersenneTwister extends Random {
185 > private readonly mt = new Array(624);
186 > private index = 0;
187 >
188 > constructor(seed: number) {
189 super();
190
195 }
196 }
197 > random.ts
198 > private _nextInt() {
199 if (this.index === 0) {
200 this.generateNumbers();
211 return y >>> 0;
212 }
213 > random.ts
214 > public nextIntRange(start: number, endExclusive: number) {
215 const range = endExclusive - start;
216 return Math.floor(this._nextInt() / (0x100000000 / range)) + start;
217 }
218 > random.ts
219 > private generateNumbers() {
220 for (let i = 0; i < 624; i++) {
221 const y = (this.mt[i] & 0x80000000) + (this.mt[(i + 1) % 624] & 0x7fffffff);