wp_rand

The timeline below displays how wordpress function wp_rand has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Generates a random non-negative number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 * @since 6.1.0 Returns zero instead of a random number if both `$min` and `$max` are zero.
 *
 * @global string $rnd_value
 *
 * @param int $min Optional. Lower limit for the generated number.
 *                 Accepts positive integers or zero. Defaults to 0.
 * @param int $max Optional. Upper limit for the generated number.
 *                 Accepts positive integers. Defaults to 4294967295.
 * @return int A random non-negative number between min and max.
 */
function wp_rand($min = null, $max = null)
{
    global $rnd_value;
    /*
     * Some misconfigured 32-bit environments (Entropy PHP, for example)
     * truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
     */
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    if (null === $min) {
        $min = 0;
    }
    if (null === $max) {
        $max = $max_random_number;
    }
    // We only handle ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method.
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $max);
            $_min = min($min, $max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    /*
     * Reset $rnd_value after 14 uses.
     * 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
     */
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value.
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range.
    $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    return abs((int) $value);
}

WordPress Version: 6.1

/**
 * Generates a random non-negative number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 * @since 6.1.0 Returns zero instead of a random number if both `$min` and `$max` are zero.
 *
 * @global string $rnd_value
 *
 * @param int $min Optional. Lower limit for the generated number.
 *                 Accepts positive integers or zero. Defaults to 0.
 * @param int $max Optional. Upper limit for the generated number.
 *                 Accepts positive integers. Defaults to 4294967295.
 * @return int A random non-negative number between min and max.
 */
function wp_rand($min = null, $max = null)
{
    global $rnd_value;
    // Some misconfigured 32-bit environments (Entropy PHP, for example)
    // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    if (null === $min) {
        $min = 0;
    }
    if (null === $max) {
        $max = $max_random_number;
    }
    // We only handle ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method.
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $max);
            $_min = min($min, $max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses.
    // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value.
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range.
    $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    return abs((int) $value);
}

WordPress Version: 5.6

/**
 * Generates a random number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32-bit environments (Entropy PHP, for example)
    // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method.
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses.
    // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value.
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range.
    if (0 != $max) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs((int) $value);
}

WordPress Version: 5.5

/**
 * Generates a random number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32-bit environments (Entropy PHP, for example)
    // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method.
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses.
    // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value.
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range.
    if (0 != $max) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 5.4

/**
 * Generates a random number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 * @staticvar string $seed
 * @staticvar bool $use_random_int_functionality
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32-bit environments (Entropy PHP, for example)
    // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method.
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses.
    // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value.
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range.
    if (0 != $max) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 5.1

/**
 * Generates a random number.
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 * @staticvar string $seed
 * @staticvar bool $use_random_int_functionality
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) '4294967295' : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle Ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses
    // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range
    if ($max != 0) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 4.5

/**
 * Generates a random number
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 * @staticvar string $seed
 * @staticvar bool $external_rand_source_available
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) "4294967295" : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle Ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguments in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses
    // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range
    if ($max != 0) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 4.4

/**
 * Generates a random number
 *
 * @since 2.6.2
 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available.
 *
 * @global string $rnd_value
 * @staticvar string $seed
 * @staticvar bool $external_rand_source_available
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) "4294967295" : 4294967295;
    // 4294967295 = 0xffffffff
    // We only handle Ints, floats are truncated to their integer value.
    $min = (int) $min;
    $max = (int) $max;
    // Use PHP's CSPRNG, or a compatible method
    static $use_random_int_functionality = true;
    if ($use_random_int_functionality) {
        try {
            $_max = (0 != $max) ? $max : $max_random_number;
            // wp_rand() can accept arguements in either order, PHP cannot.
            $_max = max($min, $_max);
            $_min = min($min, $_max);
            $val = random_int($_min, $_max);
            if (false !== $val) {
                return absint($val);
            } else {
                $use_random_int_functionality = false;
            }
        } catch (Error $e) {
            $use_random_int_functionality = false;
        } catch (Exception $e) {
            $use_random_int_functionality = false;
        }
    }
    // Reset $rnd_value after 14 uses
    // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Reduce the value to be within the min - max range
    if ($max != 0) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 4.3

/**
 * Generates a random number
 *
 * @since 2.6.2
 *
 * @global string $rnd_value
 * @staticvar string $seed
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Reset $rnd_value after 14 uses
    // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG') && !defined('WP_INSTALLING')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) "4294967295" : 4294967295;
    // 4294967295 = 0xffffffff
    // Reduce the value to be within the min - max range
    if ($max != 0) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}

WordPress Version: 3.7

/**
 * Generates a random number
 *
 * @since 2.6.2
 *
 * @param int $min Lower limit for the generated number
 * @param int $max Upper limit for the generated number
 * @return int A random number between min and max
 */
function wp_rand($min = 0, $max = 0)
{
    global $rnd_value;
    // Reset $rnd_value after 14 uses
    // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
    if (strlen($rnd_value) < 8) {
        if (defined('WP_SETUP_CONFIG')) {
            static $seed = '';
        } else {
            $seed = get_transient('random_seed');
        }
        $rnd_value = md5(uniqid(microtime() . mt_rand(), true) . $seed);
        $rnd_value .= sha1($rnd_value);
        $rnd_value .= sha1($rnd_value . $seed);
        $seed = md5($seed . $rnd_value);
        if (!defined('WP_SETUP_CONFIG')) {
            set_transient('random_seed', $seed);
        }
    }
    // Take the first 8 digits for our value
    $value = substr($rnd_value, 0, 8);
    // Strip the first eight, leaving the remainder for the next call to wp_rand().
    $rnd_value = substr($rnd_value, 8);
    $value = abs(hexdec($value));
    // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    $max_random_number = (3000000000 === 2147483647) ? (float) "4294967295" : 4294967295;
    // 4294967295 = 0xffffffff
    // Reduce the value to be within the min - max range
    if ($max != 0) {
        $value = $min + ($max - $min + 1) * $value / ($max_random_number + 1);
    }
    return abs(intval($value));
}