WeightedRandom
in package
Weighted random number generator used to make events achieve their expected rate of success faster than a pure random number generator.
The weighting is added to a random number (higher weight means that success is less likely). Therefore, when the weighted coin flip is successful, the weight is increased so that future events are less likely; similarly, when the weighted coin flip is unsuccessful, the weight is decreased so that future events are more likely.
Table of Contents
Constants
- WEIGHTING_CHANGE = 50
Properties
- $accountID : int
- $CACHE_RANDOMS : array<int, array<int, array<string, array<int, self>>>>
- $gameID : int
- $hasChanged : bool
- $type : string
- $typeID : int
- $weighting : float
Methods
- flipWeightedCoin() : bool
- Given $successChance as the base percent chance that an event happens, reduce that chance by the current weighting, and then check the result.
- getAccountID() : int
- getGameID() : int
- getType() : string
- getTypeID() : int
- getWeightedRandom() : self
- getWeightedRandomForPlayer() : self
- getWeighting() : float
- saveWeightedRandoms() : void
- update() : void
- __construct() : mixed
Constants
WEIGHTING_CHANGE
protected
mixed
WEIGHTING_CHANGE
= 50
Properties
$accountID read-only
protected
int
$accountID
$CACHE_RANDOMS
protected
static array<int, array<int, array<string, array<int, self>>>>
$CACHE_RANDOMS
= []
$gameID read-only
protected
int
$gameID
$hasChanged
protected
bool
$hasChanged
= false
$type read-only
protected
string
$type
$typeID read-only
protected
int
$typeID
$weighting
protected
float
$weighting
Methods
flipWeightedCoin()
Given $successChance as the base percent chance that an event happens, reduce that chance by the current weighting, and then check the result.
public
flipWeightedCoin(float $successChance) : bool
Parameters
- $successChance : float
Return values
boolgetAccountID()
public
getAccountID() : int
Return values
intgetGameID()
public
getGameID() : int
Return values
intgetType()
public
getType() : string
Return values
stringgetTypeID()
public
getTypeID() : int
Return values
intgetWeightedRandom()
public
static getWeightedRandom(int $gameID, int $accountID, string $type, int $typeID[, bool $forceUpdate = false ]) : self
Parameters
- $gameID : int
- $accountID : int
- $type : string
- $typeID : int
- $forceUpdate : bool = false
Return values
selfgetWeightedRandomForPlayer()
public
static getWeightedRandomForPlayer(AbstractPlayer $player, string $type, int $typeID[, bool $forceUpdate = false ]) : self
Parameters
- $player : AbstractPlayer
- $type : string
- $typeID : int
- $forceUpdate : bool = false
Return values
selfgetWeighting()
public
getWeighting() : float
Return values
floatsaveWeightedRandoms()
public
static saveWeightedRandoms() : void
update()
public
update() : void
__construct()
protected
__construct(int $gameID, int $accountID, string $type, int $typeID) : mixed
Parameters
- $gameID : int
- $accountID : int
- $type : string
- $typeID : int