Skip to content

Instantly share code, notes, and snippets.

@waquwex
Created June 6, 2024 23:45
Show Gist options
  • Select an option

  • Save waquwex/87972b586b3d93f9413c80eb367a8f86 to your computer and use it in GitHub Desktop.

Select an option

Save waquwex/87972b586b3d93f9413c80eb367a8f86 to your computer and use it in GitHub Desktop.
Random Bool
bool randomBool() {
std::random_device rd;
mt19937 generator;
if (rd.entropy() == 0) { // Fallback to using time for randomness
using namespace std::chrono;
generator = mt19937(static_cast<unsigned int>(chrono::system_clock::now().time_since_epoch().count()));
} else {
generator = mt19937(rd());
}
uniform_int_distribution<> dist(0, 1);
return static_cast<bool>(dist(generator));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment