Debian Codegraph @

vendor/ramsey/uuid/src/Generator/RandomBytesGenerator.php

raw
1 <?php
2 /**
3 * This file is part of the ramsey/uuid library
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @copyright Copyright (c) Ben Ramsey <[email protected]>
9 * @license http://opensource.org/licenses/MIT MIT
10 * @link https://benramsey.com/projects/ramsey-uuid/ Documentation
11 * @link https://packagist.org/packages/ramsey/uuid Packagist
12 * @link https://github.com/ramsey/uuid GitHub
13 */
14
15 namespace Ramsey\Uuid\Generator;
16
17 use Exception;
18
19 /**
20 * RandomBytesGenerator provides functionality to generate strings of random
21 * binary data using `random_bytes()` function in PHP 7+ or paragonie/random_compat
22 *
23 * @link http://php.net/random_bytes
24 * @link https://github.com/paragonie/random_compat
25 */
26 class RandomBytesGenerator implements RandomGeneratorInterface
27 {
28 /**
29 * Generates a string of random binary data of the specified length
30 *
31 * @param integer $length The number of bytes of random binary data to generate
32 * @return string A binary string
33 * @throws Exception if it was not possible to gather sufficient entropy
34 */
35 public function generate($length)
36 {
37 return random_bytes($length);
38 }
39 }