Home > Article > Backend Development > Five ways to generate non-repetitive random numbers in PHP
In the previous article, I introduced the method of generating random numbers in PHP. We all know that PHP random numbers are an indispensable part whether in development or in mobile applications. They are often used in daily development. Dealing with PHP random numbers, so today I will introduce to you five ways to generate PHP random numbers without repetition!
The first way:
The second way
The third way
The above can generate 5 non-repeating php random numbers between 1-20
The fourth way
The fifth way
This may be simpler than calling (ps: If the step is specified in the range long, you must pay attention to whether the second parameter of array_rand exceeds the length of $tmp).
Summary:
PHP provides a very rich set of array functions. Most PHP random numbers can be generated from the perspective of arrays. Of course If you have a better method, I hope it will be helpful to you. This article can be considered as a starting point.
Related recommendations:
#
The above is the detailed content of Five ways to generate non-repetitive random numbers in PHP. For more information, please follow other related articles on the PHP Chinese website!