Class OpenPatricianRandom
- java.lang.Object
-
- ch.sahits.game.openpatrician.utilities.OpenPatricianRandom
-
public class OpenPatricianRandom extends java.lang.Object
Supply some more specific random functions.- Author:
- Andi Hotz, (c) Sahits GmbH, 2015 Created on May 15, 2015
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Random
rnd
-
Constructor Summary
Constructors Constructor Description OpenPatricianRandom()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
nextGaussian(int upperBound)
Generate a gaussian distributed random number with a mean ofupperBound
/2 and a variance ofupperBound
/2.int
nextSlidingRandomDecreasing(int upperBound, double startProbability)
Create a random number in the range [0,upperBound
].private int
nextSlidingRandomRecreasing(int upperBound, double startProbability, double slope)
int
nextSlidingRandomSlopeDecreasing(int upperBound, double slope)
Create a random number in the range [0,upperBound
].
-
-
-
Method Detail
-
nextGaussian
public int nextGaussian(int upperBound)
Generate a gaussian distributed random number with a mean ofupperBound
/2 and a variance ofupperBound
/2. All the values are restricted to the range of [0,upperBound
].- Parameters:
upperBound
- upper bound value.- Returns:
- random int with gaussion distribution.
- See Also:
Random.nextGaussian()
-
nextSlidingRandomDecreasing
public int nextSlidingRandomDecreasing(int upperBound, double startProbability)
Create a random number in the range [0,upperBound
]. ThestartProbability
the probability for the value 0. This in turn determines the probabilities for all the other numbers, as the sum of all probabilities in the range [0,upperBound
] must sum up to 1 and the change from n to n+1 is linear.- Parameters:
upperBound
- upper limitstartProbability
- initial probability- Returns:
- next random integer
-
nextSlidingRandomSlopeDecreasing
public int nextSlidingRandomSlopeDecreasing(int upperBound, double slope)
Create a random number in the range [0,upperBound
]. Theslope
defines the linear slope from [0,upperBound
+1]. The value atupperBound
+1 is 0. This in turn determines the probabilities for all the other numbers, as the sum of all probabilities in the range [0,upperBound
] must sum up to 1 and the change from n to n+1 is linear.- Parameters:
upperBound
- upper limitslope
- of for the random limit calculation- Returns:
- next random integer
-
nextSlidingRandomRecreasing
private int nextSlidingRandomRecreasing(int upperBound, double startProbability, double slope)
-
-