Here is the case when all map items must be access in random order.
- Copy the map to a vector.
- Shuffle vector.
In pseudo-code (It closely reflects the following C++ implementation):
import random
import time
# populate map by some stuff for testing
m = dict((i*i, i) for i in range(3))
# copy map to vector
v = m.items()
# seed PRNG
# NOTE: this part is present only to reflect C++
r = random.Random(time.clock())
# shuffle vector
random.shuffle(v, r.random)
# print randomized map elements
for e in v:
print "%s:%s" % e,
print
In C++:
#include
#include
#include