Documentation

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

Properties

$CACHE_RANDOMS

protected static array<int, array<int, array<string, array<int, self>>>> $CACHE_RANDOMS = []

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
bool

getWeightedRandom()

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
self

getWeightedRandomForPlayer()

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
self

getWeighting()

public getWeighting() : float
Return values
float

saveWeightedRandoms()

public static saveWeightedRandoms() : void

__construct()

protected __construct(int $gameID, int $accountID, string $type, int $typeID) : mixed
Parameters
$gameID : int
$accountID : int
$type : string
$typeID : int

        
On this page

Search results