Lottery
class Lottery (View source)
Properties
protected int|float | $chances | The number of expected wins. |
|
protected int|null | $outOf | The number of potential opportunities to win. |
|
protected null|callable | $winner | The winning callback. |
|
protected null|callable | $loser | The losing callback. |
|
static protected callable|null | $resultFactory | The factory that should be used to generate results. |
Methods
Create a new Lottery instance.
Set the winner callback.
Set the loser callback.
Run the lottery.
Run the lottery.
Run the winner or loser callback, randomly.
Determine if the lottery "wins" or "loses".
The factory that determines the lottery result.
Force the lottery to always result in a win.
Force the lottery to always result in a lose.
Set the sequence that will be used to determine lottery results.
Set the sequence that will be used to determine lottery results.
Indicate that the lottery results should be determined normally.
Set the factory that should be used to determine the lottery results.
Details
void
__construct(int|float $chances, int|null $outOf = null)
Create a new Lottery instance.
static Lottery
odds(int|float $chances, int|null $outOf = null)
Create a new Lottery instance.
$this
winner(callable $callback)
Set the winner callback.
$this
loser(callable $callback)
Set the loser callback.
mixed
__invoke(mixed ...$args)
Run the lottery.
mixed
choose(null|int $times = null)
Run the lottery.
protected callable
runCallback(mixed ...$args)
Run the winner or loser callback, randomly.
protected bool
wins()
Determine if the lottery "wins" or "loses".
static protected callable
resultFactory()
The factory that determines the lottery result.
static void
alwaysWin(callable|null $callback = null)
Force the lottery to always result in a win.
static void
alwaysLose(callable|null $callback = null)
Force the lottery to always result in a lose.
static void
fix(array $sequence, callable|null $whenMissing = null)
Set the sequence that will be used to determine lottery results.
static void
forceResultWithSequence(array $sequence, callable|null $whenMissing = null)
Set the sequence that will be used to determine lottery results.
static void
determineResultNormally()
Indicate that the lottery results should be determined normally.
static void
setResultFactory(callable $factory)
Set the factory that should be used to determine the lottery results.