MCPcopy Index your code
hub / github.com/expr-lang/expr / oneOf

Function oneOf

test/gen/utils.go:18–31  ·  view source on GitHub ↗
(cases []element[T])

Source from the content-addressed store, hash-verified

16}
17
18func oneOf[T any](cases []element[T]) T {
19 total := 0
20 for _, c := range cases {
21 total += c.weight
22 }
23 r := rand.Intn(total)
24 for _, c := range cases {
25 if r < c.weight {
26 return c.value
27 }
28 r -= c.weight
29 }
30 return cases[0].value
31}
32
33func random[T any](array []T) T {
34 return array[rand.Intn(len(array))]

Callers 15

mainFunction · 0.85
nodeFunction · 0.85
integerNodeFunction · 0.85
memberNodeFunction · 0.85
callNodeFunction · 0.85
pipeNodeFunction · 0.85
builtinNodeFunction · 0.85
predicateNodeFunction · 0.85
pointerNodeFunction · 0.85
arrayNodeFunction · 0.85
mapNodeFunction · 0.85
sliceNodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…