Package software.bluelib.random
Class PityRandom
java.lang.Object
software.bluelib.random.PityRandom
WARNING: Still a massive Work in Progress.
A randomizer with a pity system to balance probability.Where
The weight decreases exponentially for values with higher selection counts, and increases for values with fewer selections, encouraging the selection of less-picked values.
A randomizer with a pity system to balance probability.
The probability of selecting a specific value decreases slightly after it is picked. The least selected value has a significantly higher chance of appearing.
Probability is adjusted using an inverse weighting system:
- The more a value has been picked, the lower its chance.
- The least picked value will always have the highest chance.
- Uses exponential scaling (2^(maxCount - count)) for smoother weight adjustment.
Supported types:
- Integer (default range-based selection)
- Boolean (weighted random true/false selection)
- Float and Double (randomized within a range, with pity weighting applied)
Probability Breakdown:
- If all values have been picked equally, they each have a 1/N chance.
- If one value has been picked more times than another, its weight is halved per additional selection.
- Example: If we have (1,2,3,4,5) and 3 has been picked twice while others once, then 3's weight is reduced by half.
Math formula for weighting:
- For each value
x, its weightw(x)is calculated as:
w(x) = 2^(maxCount - count(x))
maxCount is the highest count of selections made for any value, and count(x) is the number of times x has been selected.In other words:
- If
xhas been picked once, its weight is2^(maxCount - 1). - If
xhas been picked twice, its weight is2^(maxCount - 2). - This exponential decay ensures that values picked more frequently are less likely to be selected again, while those picked less frequently are more likely to be selected.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
PityRandom
public PityRandom(int pMin, int pMax)
-
-
Method Details
-
nextInt
public int nextInt() -
nextBoolean
public boolean nextBoolean() -
nextFloat
public float nextFloat() -
nextDouble
public double nextDouble()
-