public function random($min = false, $max = false)
    {
        if ($min === false) {
            $min = new BigInteger(0);
        }
        if ($max === false) {
            $max = new BigInteger(0x7FFFFFFF);
        }
        $compare = $max->compare($min);
        if (! $compare) {
            return $this->protectedNormalize($min);
        } elseif ($compare < 0) {
            // if $min is bigger then $max, swap $min and $max
            $temp = $max;
            $max = $min;
            $min = $temp;
        }
        static $one;
        if (! isset($one)) {
            $one = new BigInteger(1);
        }
        $max = $max->subtract($min->subtract($one));
        $size = strlen(ltrim($max->toBytes(), chr(0)));
        /*
         * doing $random % $max doesn't work because some numbers will be more likely to occur than others.
         * eg. if $max is 140 and $random's max is 255 then that'd mean both $random = 5 and $random = 145
         * would produce 5 whereas the only value of random that could produce 139 would be 139. ie.
         * not all numbers would be equally likely. some would be more likely than others.
         *
         * creating a whole new random number until you find one that is within the range doesn't work
         * because, for sufficiently small ranges, the likelihood that you'd get a number within that range
         * would be pretty small. eg. with $random's max being 255 and if your $max being 1 the probability
         * would be pretty high that $random would be greater than $max.
         *
         * phpseclib works around this using the technique described here:
         *
         *
         */
        $random_max = new BigInteger(chr(1) . str_repeat("\0", $size), 256);
        $random = $this->protectedRandomNumberHelper($size);
        list ($max_multiple) = $random_max->divide($max);
        $max_multiple = $max_multiple->multiply($max);
        while ($random->compare($max_multiple) >= 0) {
            $random = $random->subtract($max_multiple);
            $random_max = $random_max->subtract($max_multiple);
            $random = $random->bitwiseLeftShift(8);
            $random = $random->add($this->protectedRandomNumberHelper(1));
            $random_max = $random_max->bitwiseLeftShift(8);
            list ($max_multiple) = $random_max->divide($max);
            $max_multiple = $max_multiple->multiply($max);
        }
        list ($random) = $random->divide($max);
        return $this->protectedNormalize($random->add($min));
    }