Skip to content

Random ​

Rasuvaeff\PropertyTesting\Random

Class — Package: property-testing-core — Source — Version: v1.0.0-1-g88fdee2

Seedable, deterministic pseudo-random number generator.

Two instances created with the same seed produce identical sequences, which is what makes counterexamples reproducible. Backed by an object-scoped Mersenne Twister (MT19937) engine via ext-random's Random\Randomizer, so it is independent of PHP's global mt_rand state — important inside a test runner where other code may draw random numbers between runs.

It also carries the Runner\EdgeCases choice, because the generators that act on it already receive this and nothing else: threading a second parameter through every ArbitraryInterface would change a published signature to say something the source of randomness can say instead.

Constructor ​

php
__construct(
    int $seed,
    \Runner\EdgeCases $edgeCases = Rasuvaeff\PropertyTesting\Runner\EdgeCases::Mixin,
)
ParameterTypeDefaultDescription
$seedintrequiredThe seed; two instances with the same one produce the same sequence.
$edgeCasesRunner\EdgeCasesRasuvaeff\PropertyTesting\Runner\EdgeCases::MixinWhether the numeric generators keep biasing toward boundary values.

Methods ​

drawsEdgeCase() ​

php
drawsEdgeCase(int $denominator): bool

Whether this draw should be an edge value rather than a uniform one.

  • $denominator — The odds: one draw in this many is an edge value.

The roll happens either way. Skipping it under Runner\EdgeCases::None would shift every later draw and make the same seed mean something else in the two modes; consuming it keeps them aligned, so switching the mode changes which values are edges and not the whole sequence.

int() ​

php
int(int $min, int $max): int

Uniform integer in the inclusive range [$min, $max].

float() ​

php
float(): float

Uniform float in the half-open range [0.0, 1.0).

bytes() ​

php
bytes(int $length): string

Random byte string of the given length (bytes in 0..255).