Skip to content

Instantly share code, notes, and snippets.

@valorad
Last active February 2, 2024 19:45
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