Skip to content

Instantly share code, notes, and snippets.

@valorad
Last active February 2, 2024 19:45
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 valorad/f24ebcf4df1973843a3368d62cef03a9 to your computer and use it in GitHub Desktop.
Save valorad/f24ebcf4df1973843a3368d62cef03a9 to your computer and use it in GitHub Desktop.
Salesforce Apex get a random Integer number ∈ [minValue, maxValue)
/**
* get a random Integer number ∈ [minValue, maxValue)
*/
public Integer getRandomNumberBetween(Integer minValue, Integer maxValue) {
if (minValue > maxValue) {
// swap position
Integer tmp = minValue;
minValue = maxValue;
maxValue = tmp;
}
return Math.floor(Math.random() * (maxValue - minValue) + minValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment