MCPcopy Index your code
hub / github.com/TeaCoder52/patcode / pickTwoDifferentDigits

Function pickTwoDifferentDigits

src/utils.ts:34–54  ·  view source on GitHub ↗
(
	digits: string[],
	rng: () => number
)

Source from the content-addressed store, hash-verified

32}
33
34export function pickTwoDifferentDigits(
35 digits: string[],
36 rng: () => number
37): [string, string] {
38 if (digits.length < 2) throw new Error('Need at least 2 different digits')
39
40 const d1 = pickDigit(digits, rng)
41 let d2 = pickDigit(digits, rng)
42 let guard = 0
43
44 while (d2 === d1 && guard++ < 20) {
45 d2 = pickDigit(digits, rng)
46 }
47
48 if (d1 === d2) {
49 const filtered = digits.filter((d) => d !== d1)
50 d2 = pickDigit(filtered, rng)
51 }
52
53 return [d1, d2]
54}
55
56export function pickThreeDifferentDigits(
57 digits: string[],

Callers 2

createCustomContextFunction · 0.90
pickThreeDifferentDigitsFunction · 0.85

Calls 1

pickDigitFunction · 0.85

Tested by

no test coverage detected