Random element in a map

前端 未结 9 672
面向向阳花
面向向阳花 2021-01-07 16:14

what is a good way to select a random element from a map? C++. It is my understanding that maps don\'t have random access iterators. The key is a long long and the map is

9条回答
  •  自闭症患者
    2021-01-07 16:43

    Maybe draw up a random key, then use lower_bound to find the closest key actually contained.

提交回复
热议问题