Total Complexity | 6 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | final class RandomIteratorAggregate implements IteratorAggregate |
||
26 | { |
||
27 | /** |
||
28 | * @var IteratorAggregate<TKey, T> |
||
29 | */ |
||
30 | private IteratorAggregate $iteratorAggregate; |
||
31 | |||
32 | private int $seed; |
||
33 | |||
34 | /** |
||
35 | * @param Iterator<TKey, T> $iterator |
||
36 | */ |
||
37 | public function __construct(Iterator $iterator, ?int $seed = null) |
||
38 | { |
||
39 | $this->iteratorAggregate = new CachingIteratorAggregate($iterator); |
||
40 | $this->seed = $seed ?? random_int(PHP_INT_MIN, PHP_INT_MAX); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return Traversable<TKey, T> |
||
45 | */ |
||
46 | public function getIterator(): Traversable |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param array<int, int> $array |
||
69 | * |
||
70 | * @return array<int, int> |
||
71 | */ |
||
72 | private function predictableRandomArray(array $array, int $seed): array |
||
81 |