Home  >  Article  >  Backend Development  >  Five ways to generate non-repetitive random numbers in PHP

Five ways to generate non-repetitive random numbers in PHP

黄舟
黄舟Original
2017-11-10 14:15:3711729browse

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:

php random number generation method


PHP random number


##php random number WeChat Red envelope random generation algorithm php version


#

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!

Statement:
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