Last active
February 2, 2024 19:45
-
-
Save valorad/f24ebcf4df1973843a3368d62cef03a9 to your computer and use it in GitHub Desktop.
Salesforce Apex get a random Integer number ∈ [minValue, maxValue)
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
/** | |
* 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