← Lararand 9 / 9

Reference

Configuration

Key Default What it is
chain ['system'] Sources in order of preference, tried left to right
block 1024 Bytes fetched per remote request
sources.*.driver Which built-in source, or your own class
sources.*.key API key, for the metered providers
sources.*.timeout 4 Seconds before handing over to the next source
sources.*.cooldown varies Seconds a refusing source is skipped for

Environment variables: LARARAND_BLOCK, QUANTUM_ANU_API_KEY, RANDOM_ORG_KEY, and a *_TIMEOUT and *_COOLDOWN per remote source.

Classes

Randomness                     the API: below, int, ints, distinct, shuffle, pick, one, float, string
Facades\Rand                   the same, statically
Contracts\RandomSource         one method, bytes(int $count): string
Exceptions\RandomnessUnavailable   thrown by a source that cannot serve

Sources\SystemSource           random_bytes
Sources\AnuPublicSource        ANU, free endpoint
Sources\AnuQuantumSource       ANU, metered endpoint
Sources\RandomOrgSource        random.org

Decorators\Buffer              one request per block instead of per draw
Decorators\Fallback            a source and what to try when it refuses
Decorators\Cooldown            skips a source that just refused

Not in scope

Signed draws. random.org can sign a result so a third party can verify it was not altered, which is the right tool for a public lottery. Doing it properly means storing signatures and offering verification, not just calling a different endpoint. If you need that today, call their API directly.

Seeding. There is no way to fix the sequence from the config, and that is deliberate: a seedable production generator is a generator someone can arrange. Substitute the source in tests instead.

built and maintained by Edu Lazaro · MIT license