Skip to content

SeededRandomness

A source of entropy that is not random at all: the same seed always produces the same sequence of SeededRandomness::bytes()/SeededRandomness::int() results, in call order.

This is what a deterministic test of anything id- or token-shaped wants — a test asserting a specific generated session id, or a replay engine reproducing a recorded CSRF token, should not depend on the real CSPRNG happening to agree with what was recorded.

Backed by Randomizer over a seeded Mt19937 engine — not cryptographically secure, which is irrelevant here: the whole point is that the sequence is reproducible, not that it is unguessable.

final class SeededRandomness implements RandomnessInterface

ImplementsRandomnessInterface
SourceSupport/Random/SeededRandomness.php

public function __construct(int $seed): mixed

ParameterTypeDescription
$seedint

Returns mixed

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].

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

$length cryptographically-random-shaped bytes.

ParameterTypeDescription
$lengthpositive-int

Returns string

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