YAROC: Yet Another Random.Org Client.

dev-master 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.


  • PHP >= 5.6,
  • A PSR-7 http client (Guzzle library or any other equivalent),
  • (optional) PHPUnit to run tests.


The first step to use yaroc is to download Composer:

$ curl -s http://getcomposer.org/installer | php

Then run the following command to install the dependencies:

$ php composer.phar 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.

To call a method, use the RandomOrgAPI::call() method. Its arguments are:

The RandomOrgAPI::call() method will check if the $method can be handled by a plugin. If you pass in unsupported or unknown values to the parameters argument, they will be ignored automatically.



require 'vendor/autoload.php';

$randomOrgAPI = new drupol\Yaroc\RandomOrgAPI();

$result = $randomOrgAPI->call('getUsage');

// Let's switch to API V2

$result = $randomOrgAPI->call('generateIntegers', ['n' => 5, 'min' => 0, 'max' => 100]);

$result = $randomOrgAPI->call('generateDecimalFractions', ['n' => 15, 'decimalPlaces' => 6]);

$result = $randomOrgAPI->call('generateStrings', ['n' => 5, 'length' => 20]);

// Let's switch back to API V1

$result = $randomOrgAPI->call('generateGaussians', ['n' => 5, 'mean' => 5, 'standardDeviation' => 3, 'significantDigits' => 3]);

$result = $randomOrgAPI->call('generateUUIDs', ['n' => 6]);

$result = $randomOrgAPI->call('generateBlobs', ['n' => 6, 'size' => 16]);

// Enable logging
$randomOrgAPI->setHttpClient(NULL, NULL, [
  new \Http\Client\Common\Plugin\LoggerPlugin(
    new \Monolog\Logger(
      [new \Monolog\Handler\StreamHandler(
        'php://stdout', \Monolog\Logger::DEBUG
    new Http\Message\Formatter\SimpleFormatter()

$result = $randomOrgAPI->call('generateSignedIntegers', ['n' => 5, 'min' => 0, 'max' => 40]);

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

Copy your API key in a file apikey at the root of the project. If you do not have it, the tests will use the temporary API key.

To run the tests, run this command:

composer phpunit


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