Created
December 11, 2022 19:33
-
-
Save jfjlaros/fd29938379ae119d05796958080082ab to your computer and use it in GitHub Desktop.
Generate a random number, but disallow the previous result.
This file contains 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
/* Generate a random number, but disallow the previous result. | |
* | |
* \param low | |
* \param high | |
* | |
* \return Random number. | |
*/ | |
long myRandom(long const low, long const high) { | |
thread_local long previousValue {random(low, high)}; | |
long value {random(low, high - 1)}; | |
if (value >= previousValue) { | |
value++; | |
} | |
previousValue = value; | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment