How to use php mt_rand function

藏色散人
Release: 2023-04-06 19:08:02
Original
3458 people have browsed it

php The mt_rand() function is used to generate random integers within a specified range. The syntax is "mt_rand();" or "mt_rand(min,max);". If no parameters are specified, a pseudo-random number between 0 and RAND_MAX is returned; if the parameters are specified, a random integer between min and max (including boundary values) is returned.

How to use php mt_rand function

How to use the mt_rand() function?

The mt_rand() function uses the Mersenne Twister algorithm to generate random integers within the specified range.

Syntax:

mt_rand(X,Y)
Copy after login

Parameters:

X represents the minimum number in the range

Y represents the maximum number in the range

Description: From Get a random number within the range of two parameters. The random number is greater than or equal to X or less than or equal to Y

php mt_rand() function example 1

<?php
$i = 1;
$j = 9;
$k = mt_rand($i,$j);
echo "取得的随机数为".$k;
?>
Copy after login

Output:

取得的随机数为5
Copy after login

php mt_rand() function example 2

<?php
$i = 10;
$j = 99;
$k = mt_rand($i,$j);
echo "取得的随机数为".$k;
?>
Copy after login

Output:

取得的随机数为24
Copy after login

The above is the detailed content of How to use php mt_rand function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!