1 | <?php |
||
14 | class ByteNumberGenerator implements NumberGenerator |
||
15 | { |
||
16 | /** @var Generator The underlying byte generator */ |
||
17 | private $byteGenerator; |
||
18 | |||
19 | /** |
||
20 | * NumberByteGenerator constructor. |
||
21 | * @param Generator $generator The underlying byte generator used to generate random bytes |
||
22 | */ |
||
23 | 91 | public function __construct(Generator $generator) |
|
27 | |||
28 | /** |
||
29 | * Tells if the underlying byte generator is supported by the system. |
||
30 | * @return bool True if the generator is supported, false if not |
||
31 | */ |
||
32 | 3 | public function isSupported() |
|
36 | |||
37 | /** |
||
38 | * Returns bytes read from the provided byte generator. |
||
39 | * @param int $count The number of bytes to read |
||
40 | * @return string A string of bytes |
||
41 | * @throws GeneratorException If there was an error generating the bytes |
||
42 | */ |
||
43 | 12 | public function getBytes($count) |
|
47 | |||
48 | /** |
||
49 | * Returns a random integer between given minimum and maximum. |
||
50 | * @param int $min The minimum possible value to return |
||
51 | * @param int $max The maximum possible value to return |
||
52 | * @return int A random number between the lower and upper limit (inclusive) |
||
53 | * @throws \InvalidArgumentException If the provided values are invalid |
||
54 | * @throws GeneratorException If an error occurs generating the number |
||
55 | */ |
||
56 | 36 | public function getNumber($min, $max) |
|
71 | |||
72 | /** |
||
73 | * Returns a random number generated using the random byte generator. |
||
74 | * @param int $limit Maximum value for the random number |
||
75 | * @return int The generated random number between 0 and the limit |
||
76 | * @throws GeneratorException If error occurs generating the random number |
||
77 | */ |
||
78 | 24 | private function getByteNumber($limit) |
|
96 | } |
||
97 |