1 | <?php |
||
29 | final class Random |
||
30 | { |
||
31 | /** |
||
32 | * Get random bytes from Mcrypt |
||
33 | * |
||
34 | * @param int $bytes Number of bytes to get |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | 19 | private static function fromMcrypt($bytes) |
|
48 | |||
49 | /** |
||
50 | * Return securely generated random bytes. |
||
51 | * |
||
52 | * @param int $bytes Number of bytes to get |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | 19 | public static function bytes($bytes) |
|
57 | { |
||
58 | 19 | if (\function_exists('random_bytes')) { |
|
59 | return \random_bytes($bytes); |
||
60 | 19 | } elseif (\function_exists('mcrypt_create_iv')) { |
|
61 | 19 | return self::fromMcrypt($bytes); |
|
62 | } |
||
63 | |||
64 | self::toss(); // @codeCoverageIgnore |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Throw an error when a failure occurs. |
||
69 | * |
||
70 | * @codeCoverageIgnore |
||
71 | */ |
||
72 | private static function toss() |
||
77 | |||
78 | /** |
||
79 | * Deterministic seeded array shuffle function. |
||
80 | * |
||
81 | * @param array $array |
||
82 | * @param string $seed |
||
83 | * @param int $mode |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public static function shuffle($array, $seed, $mode = MT_RAND_PHP) |
||
113 | } |
||
114 |