[Haskell-beginners] Picking a random element from a Map

Harald Bögeholz bo at ct.de
Wed Sep 26 09:33:26 CEST 2012


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.

Harald Bögeholz    <bo at ct.de> (PGP key available from servers)
Redaktion c't      Tel.: +49 511 5352-300  Fax: +49 511 5352-417

                   int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;

                   Affe Apfel Vergaser

/* Heise Zeitschriften Verlag GmbH & Co. KG * Karl-Wiechert-Allee 10 *
   30625 Hannover * Registergericht: Amtsgericht Hannover HRA 26709 *
   Persönlich haftende Gesellschafterin: Heise Zeitschriften Verlag *
   Geschäftsführung GmbH * Registergericht: Amtsgericht Hannover, HRB
   60405 * Geschäftsführer: Ansgar Heise, Dr. Alfons Schräder */

More information about the Beginners mailing list