You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
644 B

package de.srsoftware.web4rail;
import java.util.Map;
import org.json.JSONObject;
/**
* Class for integer ranges (min…max)
* @author Stephan Richter
*/
public class Range extends BaseClass{
private static final String MAX = "max";
private static final String MIN = "min";
public int min=0,max=10000;
public JSONObject json() {
return new JSONObject(Map.of(MIN,min,MAX,max));
}
public Range load(JSONObject json) {
min = json.getInt(MIN);
max = json.getInt(MAX);
return this;
}
public int random() {
return min + random.nextInt(max - min);
}
@Override
public String toString() {
return min+"…"+max;
}
}