Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #250 Pick a random value from a map

Choose a value x from map m.
m must not be empty. Ignore the keys.

var arr = m.Values.ToArray();
var x = arr[Random.Shared.NextInt64(0, arr.Length)];

New implementation...
< >
programming-idioms.org