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).
Synopsis
Section titled “Synopsis”interface RandomnessInterface
| Implemented by | SeededRandomness, SystemRandomness |
| Source | Support/Random/RandomnessInterface.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
bytes(positive-int $length): string | $length cryptographically-random-shaped bytes. |
int(int $min, int $max): int | A random integer in the inclusive range [$min, $max]. |
bytes()
Section titled “bytes()”abstract public function bytes(positive-int $length): string
$length cryptographically-random-shaped bytes.
| Parameter | Type | Description |
|---|---|---|
$length | positive-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.
| Parameter | Type | Description |
|---|---|---|
$min | int | |
$max | int |
Returns int