Current Location: Home> Function Categories> random_int

random_int

Generate encrypted secure pseudo-random integers
Name:random_int
Category:CSPRNG pseudo-random number generator
Programming Language:php
One-line Description:Generate a random integer whose range is specified by two parameters

Function name: random_int()

Applicable version: PHP 7.0.0 and above

Function Description: The random_int() function is used to generate a random integer whose range is specified by two parameters.

parameter:

  1. $min (required): Specifies the minimum value of the generated random integer.
  2. $max (required): Specifies the maximum value of the generated random integer.

Return value: Returns the generated random integer.

Example usage:

 // 生成一个范围在1到100之间的随机整数$randomNumber = random_int(1, 100); echo $randomNumber; // 生成一个范围在-50到50之间的随机整数$randomNumber = random_int(-50, 50); echo $randomNumber;

In the above example, the random_int() function is used to generate a random integer in a specified range. The first example generates a random integer with a range of 1 to 100, while the second example generates a random integer with a range of -50 to 50. The generated random number will be stored in the variable $randomNumber and output to the screen through an echo statement. Note that the generated random integer will always be an integer, not a floating point number.

Similar Functions
Popular Articles