src/QCheck/Generator.php
public static function frequency()
    {
        $args = func_get_args();
        $argc = count($args);
        if ($argc < 2 || $argc % 2 != 0) {
            throw new \InvalidArgumentException();
        }
        $total = array_sum(FP::realize(FP::takeNth(2, $args)));
        $pairs = FP::realize(FP::partition(2, $args));
        return self::choose(1, $total)->bindGen(
            function (RoseTree $rose) use ($pairs) {
                $n = $rose->getRoot();
                foreach ($pairs as $pair) {
                    list($chance, $gen) = $pair;
                    if ($n <= $chance) {
                        return $gen;
                    }
                    $n = $n - $chance;
                }
            }
        );
    }
public static function frequency()
    {
        $args = func_get_args();
        $argc = count($args);
        if ($argc < 2 || $argc % 2 != 0) {
            throw new \InvalidArgumentException();
        }
        $total = array_sum(FP::realize(FP::takeNth(2, $args)));
        $pairs = FP::realize(FP::partition(2, $args));
        return self::choose(1, $total)->bindGen(
            function (RoseTree $rose) use ($pairs) {
                $n = $rose->getRoot();
                foreach ($pairs as $pair) {
                    list($chance, $gen) = $pair;
                    if ($n <= $chance) {
                        return $gen;
                    }
                    $n = $n - $chance;
                }
            }
        );
    }
public static function frequency ( ) { $ args = func_get_args ( ) ; $ argc = count ( $ args ) ; if ( $ argc < 2 || $ argc % 2 != 0 ) { throw new \ InvalidArgumentException ( ) ; } $ total = array_sum ( FP :: realize ( FP :: takeNth ( 2 , $ args ) ) ) ; $ pairs = FP :: realize ( FP :: partition ( 2 , $ args ) ) ; return self :: choose ( 1 , $ total ) -> bindGen ( function ( RoseTree $ rose ) use ( $ pairs ) { $ n = $ rose -> getRoot ( ) ; foreach ( $ pairs as $ pair ) { list ( $ chance , $ gen ) = $ pair ; if ( $ n <= $ chance ) { return $ gen ; } $ n = $ n - $ chance ; } } ) ; }
creates a generator that produces values from specified generators based on
likelihoods. The likelihood of a generator being chosen is its likelihood divided
by the sum of all likelihoods.

Example:
Gen::frequency(
5, Gen::ints(),
3, Gen::booleans(),
2, Gen::alphaStrings()
)

@return Generator
creates a generator that produces values from specified generators based on likelihoods . The likelihood of a generator being chosen is its likelihood divided by the sum of all likelihoods .