Ouzo\Utilities\Functions::random PHP Method

random() public static method

public static random ( $min, $max = null )
    public static function random($min = 0, $max = null)
    {
        return function () use($min, $max) {
            return mt_rand($min, $max);
        };
    }

Usage Example

Esempio n. 1
0
 /**
  * @test
  */
 public function shouldGenerateRandomNumberInRange()
 {
     for ($i = 0; $i < 100; ++$i) {
         //given
         $function = Functions::random(3, 7);
         //when
         $result = $function();
         //then
         $this->assertGreaterThanOrEqual(3, $result);
         $this->assertLessThanOrEqual(7, $result);
     }
 }