Skip to content

SystemRandomness

The real source of entropy: SystemRandomness::bytes()/SystemRandomness::int() answer from PHP’s CSPRNG exactly like random_bytes()/random_int() always did.

This is what the container binds RandomnessInterface to by default; nothing here is mockable, which is the point — tests reach for SeededRandomness instead of stubbing this class.

final class SystemRandomness implements RandomnessInterface

ImplementsRandomnessInterface
SourceSupport/Random/SystemRandomness.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].

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