略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: gmp_random_range

2024-11-15

gmp_random_range

(PHP 5 >= 5.6.3, PHP 7, PHP 8)

gmp_random_rangeRandom number

说明

gmp_random_range(GMP|int|string $min, GMP|int|string $max): GMP

Generate a random number. The number will be between min and max.

min and max can both be negative but min must always be less than max.

参数

min

A GMP number representing the lower bound for the random number

max

A GMP number representing the upper bound for the random number

返回值

A random GMP number.

范例

示例 #1 gmp_random_range() example

<?php
$rand1 
gmp_random_range(0100);    // random number between 0 and 100
$rand2 gmp_random_range(-100, -10); // random number between -100 and -10

echo gmp_strval($rand1) . "\n";
echo 
gmp_strval($rand2) . "\n";
?>

以上例程会输出:

42
-67
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.gmp-random-range.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3