
26 Sep
2012
26 Sep
'12
4:09 a.m.
Hi Harald,
how do I (quickly) pick a random element from a `Data.Map.Map`?
Right now I am using `head $ Map.keys p` to get the first element, but I'd like to replace this by a random element.
I know I have to drag around the state of the random generator somewhere, but if I have one I am wondering what's the best way to use one to take a pick from the map.
M.keys map !! randomValue `mod` M.size map But if you need a high performance solution than it's more appropriate to put the values into a Data.Vector and indexing into it. Greetings, Daniel