Thursday, March 1, 2012

C++ map random value

This code shows how can you get a random value out of a C++ map structure


map<string, int> myMap;
 /*
  * Put code here that fills the map
  */
map<string, int>::iterator iter = myMap.begin();
map<string, int>::size_type myMapSize;
myMapSize = myMap.size();
int random_integer =  intrand(myMapSize);
advance(iter,random_integer);
cout <<iter->first;