help me find the meaning and efficiency
I found a strange function for generating a random value $code = $this->secureRandValue(1000, 9999) and decided to look at the implementation protected function secureRandValue($min, $max) { $range = $max - $min; if ($range == 0) return $min; // not so random... $log = log($range, 2); $bytes = (int)($log / 8) + 1; // length in bytes $bits = (int)$log + 1; // length in bits $filter = (int)(1 << $bits) - 1; // set all lower bits to 1 do { $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes, $s))); $rnd = $rnd & $filter; // discard irrelevant bits } while ($rnd >= $range); return $min + $rnd; } smoked for a long time and thought about the essence of the universe....