YAROC: Yet Another Random.Org Client.

1.0.0 2017-02-04 08:11 UTC


Build Status Codacy Badge Codacy Badge Scrutinizer Code Quality Versioneye Status

Yet Another Random.Org Client.

YAROC fully supports V1 and V2 API.

Most of the classes of this library are stateless and immutable.


  • PHP >= 7.0,
  • A PSR-7 http client (Guzzle library or any other equivalent),


The first step to use yaroc is to install the dependencies with Composer:

$ composer install

Or if you need it in an existent project, then run the following command to install the dependencies:

$ composer require drupol/yaroc php-http/guzzle6-adapter

Why do we need php-http/guzzle6-adapter ?

We are decoupled form any HTTP messaging client with help by HTTPlug. You may use any other HTTP client library that support PSR-7.


First request an API Key or use the temporary key.

The temporary API key used in the examples will be disabled when the beta ends.

You can call any API methods described in the documentation from Random.org.

Currently support all the Random.org API methods in the basic and signed APIs.



require 'vendor/autoload.php';

$generateIntegers = \drupol\Yaroc\Plugin\Provider::withResource('generateIntegers')
    ->withParameters(['n' => 10, 'min' => 0, 'max' => 100]);

$result = (new drupol\Yaroc\RandomOrgAPI())


$provider = \drupol\Yaroc\Plugin\Provider::withResource('generateStrings')
        'n' => 10,
        'length' => 15,
        'characters' => implode(array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9))),

$result = (new drupol\Yaroc\RandomOrgAPI())


// To use the upcoming version 2 of the random.org's API:

$result = (new drupol\Yaroc\RandomOrgAPI())


Providing the API key can be accomplished using a .env file. Copy the .env.dist file into .env and modify the latter accordingly.

Third party libraries integration

ircmaxell/RandomLib integration

YAROC provides a Source for ircmaxell/RandomLib.


require 'vendor/autoload.php';

$randomLib = new RandomLib\Factory();
$generator = $randomLib->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::HIGH))
  ->addSource(new \drupol\Yaroc\Plugin\RandomLib\Source\RandomOrg());
$randomString = $generator->generateString(10);

echo $randomString;

rchouinard/rych-random integration

YAROC provides a Generator for rchouinard/rych-random.


require 'vendor/autoload.php';

$rychRandom = new Rych\Random\Random(new \drupol\Yaroc\Plugin\RychRandom\Generator\RandomOrg());
$randomString = $rychRandom->getRandomString(8);

echo $randomString;

Tests coverage

Make a copy of the file .env.dist into .env and set your API in it. If you do not have it, the tests will use the temporary API key.

To run the tests, run this command:

composer grumphp


I discovered the Random.Org the 22 November 2016, by chance and I found the idea amazing.

I had the idea to build a library that would be following the best development practice and up to date.

Feel free to contact me at: pol.dellaiera@protonmail.com


  • Documentation
  • Tests coverage