Based on the mentioned range value (for eg: range value is 3 - 50)I have a requirement to generate random range values For instance i have a range value 3-50.
So my intention is to pick a random range in between 3-50 it may be any value like 4-48, 10-30 or vice versa.
Code Iam using
int firstRangeNo = 0;
int secondRangeNo = 0;
String rangeValues = "1-100"
String[] ranges = rangeValues.split("_");
int minRange = Integer.parseInt(ranges[0]);
int maxRange = Integer.parseInt(ranges[1]);
// Generate random range values based on the minimum and maximum values
do {
firstRangeNo = random.nextInt((maxRange - minRange) + 1) + minRange;
secondRangeNo = random.nextInt((maxRange - minRange) + 1) + minRange;
} while (firstRangeNo > secondRangeNo || firstRangeNo == secondRangeNo);
while executing this code randomly am getting below message
java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Random.java:388)
Aucun commentaire:
Enregistrer un commentaire