Skip to content

Instantly share code, notes, and snippets.

@jfjlaros
Created December 11, 2022 19:33
Show Gist options
  • Save jfjlaros/fd29938379ae119d05796958080082ab to your computer and use it in GitHub Desktop.
Save jfjlaros/fd29938379ae119d05796958080082ab to your computer and use it in GitHub Desktop.
Generate a random number, but disallow the previous result.
/* 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