Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
def main(m) do
m
|> Map.values()
|> Enum.random()
end
import "sync"
var mu sync.RWMutex
func pick(m map[int]any) any {
mu.RLock()
defer mu.RUnlock()
for _, v := range m {
return v
}
return nil
}
func pick[K comparable, V any](m map[K]V) V {
k := rand.Intn(len(m))
i := 0
for _, x := range m {
if i == k {
return x
}
i++
}
panic("unreachable")
}
// Objects
const values = Object.values(m);
// Maps
const values = [...m.values()];
const x = values[~~(Math.random() * values.length)]
@vals = values %m;
$x = $vals[ int rand @vals ];
x = m.values.sample