Skip to content

RandomnessInterface

The one seam every direct random_bytes()/random_int() call site on the request path is meant to go through instead.

Mirrors ClockInterface’s role for time(): production gets SystemRandomness, a test or a replay engine swaps in SeededRandomness so a session id, a correlation id or a CSRF token comes out the same on every run.

Deliberately just two primitives — raw bytes and a bounded integer — since every current call site reduces to one or the other (a byte string that gets base64/hex-encoded, or a probability roll).

interface RandomnessInterface

Implemented bySeededRandomness, SystemRandomness
SourceSupport/Random/RandomnessInterface.php
MethodDescription
bytes(positive-int $length): string$length cryptographically-random-shaped bytes.
int(int $min, int $max): intA random integer in the inclusive range [$min, $max].

abstract public function bytes(positive-int $length): string

$length cryptographically-random-shaped bytes.

ParameterTypeDescription
$lengthpositive-int

Returns string

abstract public function int(int $min, int $max): int

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

Replaces a direct random_int($min, $max) call.

ParameterTypeDescription
$minint
$maxint

Returns int