Installation
composer require edulazaro/lararand php artisan vendor:publish --tag=lararand-config
PHP 8.2 and Laravel 12. No dependencies beyond the framework: the remote sources use Laravel's own HTTP client and the cooldown uses your default cache.
The service provider registers itself. Out of the box the chain is ['system'], so it uses random_bytes and nothing leaves the machine.
Choosing a source
// config/lararand.php 'chain' => ['anu_public', 'system'],
anu_public is the Australian National University's free endpoint and needs no account at all, so that one line is the whole setup.
For the metered providers, put the keys in .env:
QUANTUM_ANU_API_KEY=... RANDOM_ORG_KEY=...
Keys come from quantumnumbers.anu.edu.au/api-key and api.random.org/dashboard. A source with no key is skipped rather than attempted, so listing one you have not signed up for costs nothing but does nothing either.
Pin the test suite to system
Do this before anything else:
'chain' => ['system'],
An external generator in a test suite spends quota on nothing, makes the suite slow, and makes it fail on somebody else's bad day rather than on your bugs.
Using it
The facade:
use EduLazaro\Lararand\Facades\Rand; Rand::int(1, 6);
Or inject the class, wherever you would rather say what you depend on:
use EduLazaro\Lararand\Randomness; public function __construct(private readonly Randomness $rand) {}
Injecting is also what lets a test substitute it with a bind, which is how you assert exact numbers instead of ranges.