Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php generate random numbers within a specified range

Shulou Source: shulou.com Published: 2022-06-03 18:19:04 11月12日 Update

This article introduces the knowledge of "how php generates random numbers within a specified range". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There are two ways to generate random numbers in php, one classic function is called rand (), and the other better function is mt_rand ().

Example 1

The code is as follows

$random = rand (05.1000)

Or

Example 2

The code is as follows

Srand ((double) microtime () * 1000000); $random = rand (0mem1000)

Example 3

The code is as follows

/ * get multiple random numbers in a certain range * / function yang_numberRand ($begin = 0, $end = 20, $limit = 5) {$rand_array = range ($begin, $end); shuffle ($rand_array); / / call the ready-made array random permutation function return array_slice ($rand_array, 0, $limit) / / intercepting the first $limit} "how to generate random numbers in a specified range by php" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Range random number generation code function content more knowledge practicality achievement next dilemma multiple actual situation number array article method case Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Huawei Redmi MariaDB