PHPackages                             riimu/kit-securerandom - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. riimu/kit-securerandom

ActiveLibrary[Security](/categories/security)

riimu/kit-securerandom
======================

Library for leveraging available secure random generators

v1.3.1(8y ago)733.3k↓26.7%1MITPHPPHP &gt;=5.6.0

Since Jul 10Pushed 8y ago2 watchersCompare

[ Source](https://github.com/Riimu/Kit-SecureRandom)[ Packagist](https://packagist.org/packages/riimu/kit-securerandom)[ Docs](http://kit.riimu.net)[ RSS](/packages/riimu-kit-securerandom/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (8)Used By (1)

Secure Random Generator
=======================

[](#secure-random-generator)

*SecureRandom* is a PHP library for generating secure random numbers and using them for common randomization operations such as shuffling arrays or generating string sequences like passwords. Prior to version 7.0, PHP did not have built in secure random functions, but it was still possible to use different sources of randomness for generating secure random values. Thus, this library has two main purposes:

- To provide a common interface for different sources of secure randomness across different platforms and PHP versions
- To make it easier to properly use the sources of randomness to generate random values and to perform common random array operations.

This library does not provide any additional secure random byte generators. It simply uses the byte generators that are available to PHP via extensions or internally. The four generators that are commonly available to PHP are:

- CSPRNG functions provided by PHP 7.0
- reading from the random device `/dev/(u)random`
- calling the `mcrypt_create_iv()` function
- calling the `openssl_random_pseudo_bytes()` function

The security of the randomness generated by this library is entirely dependant on the underlying random byte generator. The library does not do any additional transformations on the bytes other than the normalization needed to generate even distributions of random numbers.

The API documentation is available at:

[![Travis](https://camo.githubusercontent.com/a74a45e7fcbb3f5096cebbd0a9e3a462a56d750a064ce863cc423cc2a821b239/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f5269696d752f4b69742d53656375726552616e646f6d2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Riimu/Kit-SecureRandom)[![Scrutinizer](https://camo.githubusercontent.com/866013597d06e1f4100360df341b01b17be4c62345c1943b9773302c4f92b04a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f5269696d752f4b69742d53656375726552616e646f6d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-SecureRandom/)[![Scrutinizer Coverage](https://camo.githubusercontent.com/c7bae32ed9daf3d59de48426334a970e177e2840010c1f3a59ae18560456e095/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f5269696d752f4b69742d53656375726552616e646f6d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Riimu/Kit-SecureRandom/)[![Packagist](https://camo.githubusercontent.com/5fe32934b293bcb26c3af6e56532751d1cf825523d754068576a48590615f245/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7269696d752f6b69742d73656375726572616e646f6d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riimu/kit-securerandom)

Requirements
------------

[](#requirements)

- The minimum supported PHP version is 5.6
- The library depends on the following PHP Extensions
    - [`OpenSSL`](http://php.net/manual/en/book.openssl.php) (To use OpenSSQL generator)
    - [`Mcrypt`](http://php.net/manual/en/book.mcrypt.php) (To use Mcrypt generator)
- The `/dev/urandom` must be readable in order to use the Random reader generator

Installation
------------

[](#installation)

### Installation with Composer

[](#installation-with-composer)

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

1. Acquire the `composer.phar` by running the Composer [Command-line installation](https://getcomposer.org/download/)in your project root.
2. Once you have run the installation script, you should have the `composer.phar`file in you project root and you can run the following command:

    ```
    php composer.phar require "riimu/kit-securerandom:^1.3"

    ```

After installing this library via Composer, you can load the library by including the `vendor/autoload.php` file that was generated by Composer during the installation.

### Adding the library as a dependency

[](#adding-the-library-as-a-dependency)

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following `composer.json` file to your project and running the `composer install` command:

```
{
    "require": {
        "riimu/kit-securerandom": "^1.3"
    }
}
```

### Manual installation

[](#manual-installation)

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the [latest release](https://github.com/Riimu/Kit-SecureRandom/releases/latest)and extracting the `src` folder to your project. You may then include the provided `src/autoload.php` file to load the library classes.

Usage
-----

[](#usage)

Usage of the library is very simple. Simply create an instance of the `SecureRandom` and call any of the methods to generate random values. For example:

```
