Skip to content

Instantly share code, notes, and snippets.

@dcbishop
Forked from jrandom/gist:b4dd0d0f8200217c44d1
Created December 24, 2014 11:11
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 dcbishop/6ddf0edf881ca3fddb6f to your computer and use it in GitHub Desktop.
Save dcbishop/6ddf0edf881ca3fddb6f to your computer and use it in GitHub Desktop.
template < typename value_t >
void BogoSort( std::vector< value_t > & data )
{
while( !std::is_sorted(data.cbegin(), data.cend()) )
{
std::shuffle(data.begin(), data.end());
}
}
@jrandom
Copy link

jrandom commented Dec 24, 2014

std::shuffle() requires a third parameter that provides uniform random numbers!

http://en.cppreference.com/w/cpp/algorithm/random_shuffle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment