src/Generator/CombGenerator.php
public function generate($length)
    {
        if ($length < self::TIMESTAMP_BYTES || $length < 0) {
            throw new \InvalidArgumentException('Length must be a positive integer.');
        }

        $hash = '';

        if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) {
            $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES);
        }

        $lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT);

        return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime);
    }
public function generate($length)
    {
        if ($length < self::TIMESTAMP_BYTES || $length < 0) {
            throw new \InvalidArgumentException('Length must be a positive integer.');
        }

        $hash = '';

        if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) {
            $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES);
        }

        $lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT);

        return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime);
    }
public function generate ( $ length ) { if ( $ length < self :: TIMESTAMP_BYTES || $ length < 0 ) { throw new \ InvalidArgumentException ( 'Length must be a positive integer.' ) ; } $ hash = '' ; if ( self :: TIMESTAMP_BYTES > 0 && $ length > self :: TIMESTAMP_BYTES ) { $ hash = $ this -> randomGenerator -> generate ( $ length - self :: TIMESTAMP_BYTES ) ; } $ lsbTime = str_pad ( $ this -> converter -> toHex ( $ this -> timestamp ( ) ) , self :: TIMESTAMP_BYTES * 2 , '0' , STR_PAD_LEFT ) ; return hex2bin ( str_pad ( bin2hex ( $ hash ) , $ length - self :: TIMESTAMP_BYTES , '0' ) . $ lsbTime ) ; }
Generates a string of binary data of the specified length

@param integer $length The number of bytes of random binary data to generate
@return string A binary string
@throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
@throws \InvalidArgumentException if length is not a positive integer
@throws \Exception
Generates a string of binary data of the specified length