Total Complexity | 10 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class Demo |
||
11 | { |
||
12 | /** |
||
13 | * Demo Random Data |
||
14 | * |
||
15 | * @param array $data |
||
16 | * @param int $totalPoints |
||
17 | * @return array |
||
18 | */ |
||
19 | public static function getRandomData($data = [], $totalPoints = 100) |
||
20 | { |
||
21 | if (is_null($data)) { |
||
|
|||
22 | $data = []; |
||
23 | } |
||
24 | if (count($data) > 0) { |
||
25 | $data = array_slice($data, 1); |
||
26 | } |
||
27 | $randomWalk = self::randomWalk($totalPoints, $data); |
||
28 | // Zip the generated y values with the x values |
||
29 | $res = []; |
||
30 | foreach ($randomWalk as $key => $items) { |
||
31 | $items[0] = $key; |
||
32 | $res[] = $items; |
||
33 | } |
||
34 | return $res; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Do a random walk |
||
39 | * |
||
40 | * @param array $data |
||
41 | * @param int $totalPoints |
||
42 | * @return array |
||
43 | */ |
||
44 | public static function randomWalk($totalPoints = 100, $data = []) |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Calculating a random floating point number |
||
63 | * |
||
64 | * @param int $min |
||
65 | * @param int $max |
||
66 | * @return float|int|mixed |
||
67 | */ |
||
68 | public static function randomFloat($min = 0, $max = 1) |
||
71 | } |
||
72 | } |
||
73 |