Skip to content

Instantly share code, notes, and snippets.

@alepez
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/5c4ca1a35b22bbbe34eb to your computer and use it in GitHub Desktop.
Save alepez/5c4ca1a35b22bbbe34eb to your computer and use it in GitHub Desktop.
pickRandom
template<typename T>
T pickRandom(std::vector<T>&& vec) {
return vec[::rand() % vec.size()];
}
template<typename T>
T pickRandom(std::initializer_list<T>&& list) {
return pickRandom(std::vector<T>(std::move(list)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment