TYPO3 CMS  TYPO3_8-7
Random.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 class Random
22 {
29  public function generateRandomBytes(int $length): string
30  {
31  return random_bytes($length);
32  }
33 
41  public function generateRandomInteger(int $min, int $max): int
42  {
43  return random_int($min, $max);
44  }
45 
52  public function generateRandomHexString(int $length): string
53  {
54  return substr(bin2hex($this->generateRandomBytes((int)(($length + 1) / 2))), 0, $length);
55  }
56 }
generateRandomBytes(int $length)
Definition: Random.php:29
generateRandomInteger(int $min, int $max)
Definition: Random.php:41
generateRandomHexString(int $length)
Definition: Random.php:52