Skip to content

Randomness

Static facade over the process-wide source of entropy, mirroring Clock.

CorrelationId is fully static (no constructor, no container) by design — its own docblock states it is kept pure and dependency-free so it is unit testable without a bootstrapped Context. This is its way in. Code that can accept a collaborator should take a RandomnessInterface constructor parameter instead — it is injectable, swappable and testable in isolation — and reach for this only where threading one through is not practical.

Deliberately not read from the DI container, for the same reason Clock is not: a fully static call site has no request-scoped Context to resolve through in general, and Quiote\Context::registerCoreServicesInContainer() seeds the container’s own RandomnessInterface binding from Randomness::instance(), not the other way round, so installing a source of randomness here before bootstrap also reaches the container.

final class Randomness

SourceSupport/Random/Randomness.php
MethodDescription
instance(): RandomnessInterfaceThe randomness backing the facade, created on first use.
useRandomness(?RandomnessInterface $randomness): ?RandomnessInterfaceInstall a source of randomness for the facade to delegate to.

public static function instance(): RandomnessInterface

The randomness backing the facade, created on first use.

Returns RandomnessInterface

public static function useRandomness(?RandomnessInterface $randomness): ?RandomnessInterface

Install a source of randomness for the facade to delegate to.

The seam for a test that needs reproducible output. Pass null to drop the current one, so the next access starts from a fresh SystemRandomness.

ParameterTypeDescription
$randomness?RandomnessInterface

Returns ?RandomnessInterface — The source that was installed before this call, so a caller can restore it.