Here's a seemingly trivial coding task that I just can't seem to find an elegant solution for. Perhaps it's a Sunday afternoon 'dumbness' thing but I'm just not seeing it.
I have a Map that represents a set of names for a group:
1. Map<String, Set<String>> namesForGroup;
With content that looks something like this:
1 {"Grp1": {"a", "b", "c", "d"},
2 "Grp2": {"e", "f", "g", "h"}}
What I'd like is an elegant way to extract a random Key Value pair from that Map. For example:
1 ["Grp1", "a"]
2 ["Grp1", "d"]
3 ["Grp2", "g"]
4 ["Grp1", "c"]
5 ["Grp2", "e"]
There is no requirement for any strong randomness or any even distribution of the chosen values. A rough approximation is all that is required as I'm just generating some test data for a performance benchmark I'm writing for a new feature I've written at work.
Thanks