PHPackages                             paragonie/random\_compat - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. paragonie/random\_compat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

paragonie/random\_compat
========================

PHP 5.x polyfill for random\_bytes() and random\_int() from PHP 7

v9.99.100(5y ago)8.2k655.0M—2.9%149[5 issues](https://github.com/paragonie/random_compat/issues)20MITPHPPHP &gt;= 7CI failing

Since Jul 7Pushed 2mo ago35 watchersCompare

[ Source](https://github.com/paragonie/random_compat)[ Packagist](https://packagist.org/packages/paragonie/random_compat)[ RSS](/packages/paragonie-random-compat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (62)Used By (20)Security (1)

random\_compat
==============

[](#random_compat)

[![Build Status](https://github.com/paragonie/random_compat/actions/workflows/ci.yml/badge.svg)](https://github.com/paragonie/random_compat/actions)[![Scrutinizer](https://camo.githubusercontent.com/38350ce871986130f3597da13d6283f5072a2afada220e310e5cf9599807087e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70617261676f6e69652f72616e646f6d5f636f6d7061742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/paragonie/random_compat)[![Latest Stable Version](https://camo.githubusercontent.com/0dbc85b882320c23eaff5fde37f24d4e56bd69becdcde1e6767a55e6407a5ee9/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f72616e646f6d5f636f6d7061742f762f737461626c65)](https://packagist.org/packages/paragonie/random_compat)[![Latest Unstable Version](https://camo.githubusercontent.com/85229eebef282cd061edfd73a2adb4b814ccc6957e52da7a48d5e6aa148a8a4a/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f72616e646f6d5f636f6d7061742f762f756e737461626c65)](https://packagist.org/packages/paragonie/random_compat)[![License](https://camo.githubusercontent.com/68716067fe637df869f4594c30b2d6db2b2324f03605bfb276f352fc746080f2/68747470733a2f2f706f7365722e707567782e6f72672f70617261676f6e69652f72616e646f6d5f636f6d7061742f6c6963656e7365)](https://packagist.org/packages/paragonie/random_compat)[![Downloads](https://camo.githubusercontent.com/ee46dfe7a41bee8ed414a6b48c2f765bc728e2d6b523ec40b900d76d245e2613/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70617261676f6e69652f72616e646f6d5f636f6d7061742e737667)](https://packagist.org/packages/paragonie/random_compat)

PHP 5.x polyfill for `random_bytes()` and `random_int()` created and maintained by [Paragon Initiative Enterprises](https://paragonie.com).

Although this library *should* function in earlier versions of PHP, we will only consider issues relevant to [supported PHP versions](https://secure.php.net/supported-versions.php). **If you are using an unsupported version of PHP, please upgrade as soon as possible.**

Important
---------

[](#important)

Although this library has been examined by some security experts in the PHP community, there will always be a chance that we overlooked something. Please ask your favorite trusted hackers to hammer it for implementation errors and bugs before even thinking about deploying it in production.

**Do not use the master branch, use a [stable release](https://github.com/paragonie/random_compat/releases/latest).**

For the background of this library, please refer to our blog post on [Generating Random Integers and Strings in PHP](https://paragonie.com/blog/2015/07/how-safely-generate-random-strings-and-integers-in-php).

### Usability Notice

[](#usability-notice)

If PHP cannot safely generate random data, this library will throw an `Exception`. It will never fall back to insecure random data. If this keeps happening, upgrade to a newer version of PHP immediately.

Installing
----------

[](#installing)

**With [Composer](https://getcomposer.org):**

```
# For libraries and frameworks that support PHP 5 but may be used by
# other software that only supports PHP 7:
composer require paragonie/random_compat:\>=2

# For software that explicitly needs PHP 5 support:
composer require paragonie/random_compat:\
