Total Complexity | 8 |
Total Lines | 69 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
14 | class Generate |
||
15 | { |
||
16 | /** |
||
17 | * Generate random int. |
||
18 | * |
||
19 | * @param int $minValue |
||
20 | * @param int $maxValue |
||
21 | * |
||
22 | * @return int |
||
23 | */ |
||
24 | public static function randomInt(int $minValue = 0, int $maxValue = 1000): int |
||
25 | { |
||
26 | return rand($minValue, $maxValue); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Generate random float. |
||
31 | * |
||
32 | * @param float $minValue |
||
33 | * @param float $maxValue |
||
34 | * @param int $decimalPlace |
||
35 | * |
||
36 | * @return float |
||
37 | */ |
||
38 | public static function randomFloat(float $minValue = 0.0, float $maxValue = 1000.0, int $decimalPlace = 1): float |
||
39 | { |
||
40 | |||
41 | // Decimal place can be from 1 to 5 |
||
42 | $decimalPlace = ($decimalPlace > 0 && $decimalPlace <= 5) ? $decimalPlace : 1; |
||
43 | |||
44 | $divider = (int) pow(10, $decimalPlace); |
||
45 | |||
46 | return rand(($minValue * $divider), ($maxValue * $divider)) / $divider; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Generate random string. |
||
51 | * |
||
52 | * @param int $length |
||
53 | * @param bool $includeNumbers |
||
54 | * @param bool $includeSymbols |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public static function randomString(int $length = 10, bool $includeNumbers = true, bool $includeSymbols = false): string |
||
83 | } |
||
84 | } |
||
85 |