MCPcopy Index your code
hub / github.com/nodejs/node / sampleOfTwo

Function sampleOfTwo

deps/v8/tools/clusterfuzz/js_fuzzer/random.js:84–94  ·  view source on GitHub ↗

* Returns an array with a sample of two distinct elements from an array.

(array)

Source from the content-addressed store, hash-verified

82 * Returns an array with a sample of two distinct elements from an array.
83 */
84function sampleOfTwo(array) {
85 assert(array.length >= 2);
86
87 const first = randInt(0, array.length - 1);
88 let second = randInt(1, array.length - 1);
89 if (first == second) {
90 // On a collision, we simulate a swap.
91 second = 0;
92 }
93 return [array[first], array[second]];
94}
95
96/**
97 * As above for an arbitrary number of elements with a fast implementation

Callers 2

sampleFunction · 0.85
test_random.jsFile · 0.85

Calls 2

randIntFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected