src/Generator/ClockDriftGenerator.php
public function generate($byteCount)
    {
        $bitsPerRound = 2;
        $msecPerRound = 400;
        $hashLength = 20;
        $total = $byteCount;
        $generated = '';

        do {
            $bytes = ($total > $hashLength) ? $hashLength : $total;
            $total -= $bytes;

            $entropy = rand() . uniqid(mt_rand(), true);
            $entropy .= implode('', @fstat(@fopen(__FILE__, 'r')));
            $entropy .= memory_get_usage();

            for ($i = 0; $i < 3; $i++) {
                $counter1 = microtime(true);
                $var = sha1(mt_rand());
                for ($j = 0; $j < 50; $j++) {
                    $var = sha1($var);
                }
                $counter2 = microtime(true);
                $entropy .= $counter1 . $counter2;
            }

            $rounds = (int) ($msecPerRound * 50 / (int) (($counter2 - $counter1) * 1000000));
            $iterations = $bytes * (int) (ceil(8 / $bitsPerRound));

            for ($i = 0; $i < $iterations; $i++) {
                $counter1 = microtime();
                $var = sha1(mt_rand());
                for ($j = 0; $j < $rounds; $j++) {
                    $var = sha1($var);
                }
                $counter2 = microtime();
                $entropy .= $counter1 . $counter2;
            }

            $generated .= sha1($entropy, true);
        } while ($byteCount > strlen($generated));

        $bytes = substr($generated, 0, $byteCount);

        return str_pad($bytes, $byteCount, chr(0));
    }
public function generate($byteCount)
    {
        $bitsPerRound = 2;
        $msecPerRound = 400;
        $hashLength = 20;
        $total = $byteCount;
        $generated = '';

        do {
            $bytes = ($total > $hashLength) ? $hashLength : $total;
            $total -= $bytes;

            $entropy = rand() . uniqid(mt_rand(), true);
            $entropy .= implode('', @fstat(@fopen(__FILE__, 'r')));
            $entropy .= memory_get_usage();

            for ($i = 0; $i < 3; $i++) {
                $counter1 = microtime(true);
                $var = sha1(mt_rand());
                for ($j = 0; $j < 50; $j++) {
                    $var = sha1($var);
                }
                $counter2 = microtime(true);
                $entropy .= $counter1 . $counter2;
            }

            $rounds = (int) ($msecPerRound * 50 / (int) (($counter2 - $counter1) * 1000000));
            $iterations = $bytes * (int) (ceil(8 / $bitsPerRound));

            for ($i = 0; $i < $iterations; $i++) {
                $counter1 = microtime();
                $var = sha1(mt_rand());
                for ($j = 0; $j < $rounds; $j++) {
                    $var = sha1($var);
                }
                $counter2 = microtime();
                $entropy .= $counter1 . $counter2;
            }

            $generated .= sha1($entropy, true);
        } while ($byteCount > strlen($generated));

        $bytes = substr($generated, 0, $byteCount);

        return str_pad($bytes, $byteCount, chr(0));
    }
Generate a string of random data.

@param  integer $byteCount The desired number of bytes.
@return string  Returns the generated string.