Neos\Eel\Helper\ArrayHelper::random PHP Method

random() public method

Picks a random element from the array
public random ( array $array ) : mixed
$array array
return mixed A random entry or NULL if the array is empty
    public function random(array $array)
    {
        if ($array === []) {
            return null;
        }
        $randomIndex = array_rand($array);
        return $array[$randomIndex];
    }

Usage Example

 /**
  * @test
  * @dataProvider randomExamples
  */
 public function randomWorks($array, $expected)
 {
     $helper = new ArrayHelper();
     $result = $helper->random($array);
     $this->assertEquals($expected, in_array($result, $array));
 }