Does php have a better way to generate random numbers within a specified range?

1. Specify a range of two decimal places, such as 0. 01-19999.00
2. The numbers that have already appeared can no longer appear, for example, there have been more than 1.6 numbers such as 23.44555.33 and so on
3. Randomly generate a number that is in the range and does not appear before

The general way to achieve

is to randomly generate a number in the range, and then cycle through the numbers that have appeared to see if they are repeated, and if so, regenerate them, and then compare and cycle until the resulting numbers meet the conditions.

is there any other better way? Is there such a function?

Php
Jan.21,2022

does the general method refer to this:

$NUMBERS = array();
function makeRandomNum() {
    $max = 100;
    $count = 0;
    while ($count < $max) {
        $count += 1;
        $num = rand(1,1999900) * 0.01;
        if (!isset($NUMBERS[$num])) {
            $NUMBERS[$num] = 1;
            return $num;
        }
    }
}

other methods:

  1. generate an array with all the elements, use the array_rand () function to take one at random, and then delete
  2. from the original array.
  3. or generate an array with all the elements, then disrupt it with the shuffle () function, and use array_pop () to constantly fetch random numbers
  4. .

is not clear about the scenario you are using. In theory, most of you use fpm, to destroy it once you run it. It is impossible for programs to remember the numbers that have been generated in the past, and you have to rely on third-party storage institutions, such as redis or even traditional databases.

if you use a resident memory service, you can theoretically use the php array to record and save the numbers that have been generated. Since there is no other guarantee you ask for, the only factor. Therefore, it seems to me that there is no better way than what you have said.

if you can add the time factor, the time factor is inherently unique.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebefe6-487e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebefe6-487e1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?