PHP程序在范围之间生成随机整数
随机整数生成
要生成一个随机整数,我们可以使用random_int()函数,它是PHP中的一个库函数,它接受两个参数start_value和end_value并返回一个介于start_value和end_value之间的随机整数。
示例
<?php
$start = 10;
$end = 20;
//产生10个数字
print("random integers between $start and $end...\n");
for($i=1; $i<=10; $i++)
{
print(random_int($start, $end)." ");
}
print("\n");
$start = -100;
$end = 0;
//产生10个数字
print("random integers between $start and $end...\n");
for($i=1; $i<=10; $i++)
{
print(random_int($start, $end)." ");
}
?>输出结果
random integers between 10 and 20... 15 15 16 17 10 15 15 13 14 13 random integers between -100 and 0... -84 -4 -68 -36 -18 -56 -53 -31 -98 -94
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短