paragonie/random_compat
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The paragonie/random_compat is a PHP 5.x polyfill for random_bytes()
and random_int()
from PHP 7. It aims to provide these functions from PHP 7 for use in a PHP 5 environment. Built and maintained by Paragon Initiative Enterprises, this library is intended to be used in PHP versions that are supported as per the official PHP documentation.
The library is robust, but it should be subject to rigorous security testing before it is deployed in a production environment.
To use the paragonie/random_compat library in your project, you will need to install it either manually, through a PHP Archive, or with Composer.
By using Composer, the library can be added to your project with the following commands, depending on your specific needs:
# 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:<9.99
To use the library, include it in your PHP script and then you can call the random_bytes()
and random_int()
functions. Here is an example of how you can use these functions:
# To generate a string of random bytes:
try {
$string = random_bytes(32);
} catch (Exception $e) {
// handle exception
}
# To generate a random integer between two given integers (inclusive):
try {
$int = random_int(0, 255);
} catch (Exception $e) {
// handle exception
}
Remember to handle exceptions appropriately as outlined in the provided usage examples.
Documentation for paragonie/random_compat can be found in the README file of the GitHub repository located at https://github.com/paragonie/random_compat.git. The README provides comprehensive details about the usage, the purpose, installation process, and troubleshooting tips relating to the library, making it the primary source of documentation for this PHP package.