Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment