Created
June 6, 2024 23:45
-
-
Save waquwex/87972b586b3d93f9413c80eb367a8f86 to your computer and use it in GitHub Desktop.
Random Bool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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