\CryptoManana\Core\Traits\RandomnessFloatOutputTrait

Trait FloatOutputTrait - Reusable implementation of `FloatOutputInterface`.

Summary

Methods
Properties
Constants
getProbability()
getFloat()
getPercent()
No public properties found
No constants found
calculateEpsilon()
calculateLowQualityPercent()
validateNumericOrDefault()
validateDoubleRange()
improvePoorFloatOutput()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

getProbability()

getProbability(null|integer  $precision = 10) : float

Generate a probability format float number between 0.0 and 1.0.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

Rounding precision (default => 10).

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated probability value.

getFloat()

getFloat(null|float|integer  $from = 0.0, null|float|integer  $to = null, null|integer  $precision = 8) : float

Generate a random float number in a certain range.

Note: Passing null will use the default parameter value or for precision the global system value.

Parameters

null|float|integer $from

The lowest value to be returned (default => 0.0).

null|float|integer $to

The highest value to be returned (default => (float)$this->getMaxNumber()).

null|integer $precision

Rounding precision (default => 8).

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated float value.

getPercent()

getPercent(null|integer  $precision = 2, boolean|integer  $lowerTheScope = false) : float

Generate a percentage format float number between 0.0 and 100.0.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

Rounding precision (default => 2).

boolean|integer $lowerTheScope

Flag for using a smaller calculation range.

Throws

\Exception

Validation errors.

Returns

float —

Randomly generated percentage value.

calculateEpsilon()

calculateEpsilon(null|integer  $precision = null) : float

Internal method for calculating the machine epsilon value based on the used precision.

Note: Passing null will use the global system precision value.

Parameters

null|integer $precision

The wanted precision for the machine epsilon.

Returns

float —

The machine epsilon used for floating number comparison operations.

calculateLowQualityPercent()

calculateLowQualityPercent(integer  $max) : float

Generate a low quality percentage format float number between 0.0 and 100.0.

Parameters

integer $max

The upper scope number used for internal generation.

Returns

float —

Randomly generated low quality percentage value.

validateNumericOrDefault()

validateNumericOrDefault(integer|float|null  $from, integer|float|null  $to) 

Internal method for double range supported types validation.

Parameters

integer|float|null $from

The minimum number in the wanted range.

integer|float|null $to

The maximum number in the wanted range.

Throws

\Exception

Validation errors.

validateDoubleRange()

validateDoubleRange(integer|float  $from, integer|float  $to, null|integer  $precision = 14) 

Internal method for double range validation.

Parameters

integer|float $from

The minimum number in the wanted range.

integer|float $to

The maximum number in the wanted range.

null|integer $precision

The used precision for comparison.

Throws

\Exception

Validation errors.

improvePoorFloatOutput()

improvePoorFloatOutput(float  $from, float  $to, integer  $precision) 

Improve the quality of the algorithm used for floating numbers generation.

Parameters

float $from

The lowest value to be returned.

float $to

The highest value to be returned.

integer $precision

Rounding precision for epsilon calculation.