src/Client.php
/**
     * Generates an ID using a custom generator
     *
     * @param GeneratorInterface $generator
     * @param int $size
     * @return string
     */
Generates an ID using a custom generator
@param GeneratorInterface $generator
@param int $size
@return string
Generates an ID using a custom generator @param GeneratorInterface $generator @param int $size @return string
public function produceUsing(GeneratorInterface $generator, int $size = 32): string
    {
        $alphabetLength = strlen($this->alphabet);
        $mask = (2 << log($alphabetLength - 1) / M_LN2) - 1;
        $step = (int) ceil(1.6 * $mask * $size / $alphabetLength);
        $id = '';
        while (true) {
            $bytes = $generator->random($step);
            for ($i = 1; $i <= $step; $i++) {
                $byte = $bytes[$i] & $mask;
                if (isset($this->alphabet[$byte])) {
                    $id .= $this->alphabet[$byte];
                    if (strlen($id) === $size) {
                        return $id;
                    }
                }
            }
        }
    }
public function produceUsing ( GeneratorInterface $ generator , int $ size = 32 ) : string { $ alphabetLength = strlen ( $ this -> alphabet ) ; $ mask = ( 2 << log ( $ alphabetLength - 1 ) / M_LN2 ) - 1 ; $ step = ( int ) ceil ( 1.6 * $ mask * $ size / $ alphabetLength ) ; $ id = '' ; while ( true ) { $ bytes = $ generator -> random ( $ step ) ; for ( $ i = 1 ; $ i <= $ step ; $ i ++ ) { $ byte = $ bytes [ $ i ] & $ mask ; if ( isset ( $ this -> alphabet [ $ byte ] ) ) { $ id .= $ this -> alphabet [ $ byte ] ; if ( strlen ( $ id ) === $ size ) { return $ id ; } } } } }
Generates an ID using a custom generator
 @param GeneratorInterface $generator
 @param int $size
 @return string
Generates an ID using a custom generator @param GeneratorInterface $generator @param int $size @return string