53 lines
894 B
Java
53 lines
894 B
Java
|
package velamentum.werkzeuge;
|
||
|
|
||
|
import java.util.Random;
|
||
|
|
||
|
public class Zufallsgenerator {
|
||
|
private int min;
|
||
|
private int max;
|
||
|
private int ergebnis;
|
||
|
|
||
|
public Zufallsgenerator(int pMin, int pMax) {
|
||
|
this.min = pMin;
|
||
|
this.max = pMax;
|
||
|
this.ergebnis = getRandomNumberInRange(pMin, pMax);
|
||
|
}
|
||
|
|
||
|
|
||
|
public int nenneMin() {
|
||
|
return min;
|
||
|
}
|
||
|
|
||
|
public void setzeMin(int min) {
|
||
|
this.min = min;
|
||
|
}
|
||
|
|
||
|
public int nenneMax() {
|
||
|
return max;
|
||
|
}
|
||
|
|
||
|
public void setzeMax(int max) {
|
||
|
this.max = max;
|
||
|
}
|
||
|
|
||
|
public int nenneErgebnis() {
|
||
|
return ergebnis;
|
||
|
}
|
||
|
|
||
|
public void generiereErgebnis() {
|
||
|
this.ergebnis = getRandomNumberInRange(nenneMin(), nenneMax());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
private static int getRandomNumberInRange(int pMin, int pMax) {
|
||
|
|
||
|
if (pMin >= pMax) {
|
||
|
throw new IllegalArgumentException("max must be greater than min");
|
||
|
}
|
||
|
|
||
|
Random r = new Random();
|
||
|
return r.nextInt((pMax - pMin) + 1) + pMin;
|
||
|
}
|
||
|
}
|