How to check duplicate results of a random character generator

mishad050

I have made a random character generator, but how do I check if an result is duplicate?
E.g., if I want 100000 results, how do I check if an result is not duplicate in the 100000 results?

for ($i=0; $i<$quantity; $i++){
$a = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
$b = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
$c = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
$d = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
$code = "$a-$b-$c-$d";
echo $code .'<br>';
}

Thanks in advance!

CT14.IT

Something like this maybe? Using in_array()

$previous = array();

for ($i=0; $i<$quantity; $i++){
    $unique_found = false;
    while(!$unique_found){
        $a = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
        $b = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
        $c = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);
        $d = substr(str_shuffle("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4);

        $code = "$a-$b-$c-$d";

        if(!in_array($code,$previous)){
            $unique_found = true;
            $previous[] = $code;
            echo $code .'<br>';
        }
    }

}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Random number generator check not working

분류에서Dev

Seeding the random generator for tests

분류에서Dev

random number generator in fortran

분류에서Dev

Duplicate Character Counter for an Alphanumeric

분류에서Dev

Minimum standard random generator basics

분류에서Dev

How to use a regular expression to check for duplicate characters in a string?

분류에서Dev

Regexp - How to check whether a string starts OR ends with given character?

분류에서Dev

Why is Scrapy returning duplicate results?

분류에서Dev

printing even numbers from random generator

분류에서Dev

Random number generator between two numbers - MatLab

분류에서Dev

Random Digit Generator 도움말 (Java)

분류에서Dev

Why does the "which" command give duplicate results?

분류에서Dev

Fill up string length with random character

분류에서Dev

In Excel, how do i check if cell contains at least twice the same character from a list

분류에서Dev

Deterministic random noise generator from multiple 64-bit inputs?

분류에서Dev

PHP Getting Random Gives Blank Results

분류에서Dev

What is the difference between numpy.random's Generator class and np.random methods?

분류에서Dev

Check that string contains a character from array

분류에서Dev

Javascript check for 1 special character and 2 digits

분류에서Dev

Regex that check if text has the first character equal to @

분류에서Dev

Check if String Contains New Line character

분류에서Dev

How to not insert duplicate images?

분류에서Dev

OpenGL anisotropic filtering support, contradictory check results

분류에서Dev

Compiled c++ output file displays random character at end of program?

분류에서Dev

How to select a random vector

분류에서Dev

How random options in button?

분류에서Dev

How to grep and treat meta character as normal character?

분류에서Dev

How to type * character in nano?

분류에서Dev

MySQL Random Select Query with limit returning different number of results (undesired)

Related 관련 기사

  1. 1

    Random number generator check not working

  2. 2

    Seeding the random generator for tests

  3. 3

    random number generator in fortran

  4. 4

    Duplicate Character Counter for an Alphanumeric

  5. 5

    Minimum standard random generator basics

  6. 6

    How to use a regular expression to check for duplicate characters in a string?

  7. 7

    Regexp - How to check whether a string starts OR ends with given character?

  8. 8

    Why is Scrapy returning duplicate results?

  9. 9

    printing even numbers from random generator

  10. 10

    Random number generator between two numbers - MatLab

  11. 11

    Random Digit Generator 도움말 (Java)

  12. 12

    Why does the "which" command give duplicate results?

  13. 13

    Fill up string length with random character

  14. 14

    In Excel, how do i check if cell contains at least twice the same character from a list

  15. 15

    Deterministic random noise generator from multiple 64-bit inputs?

  16. 16

    PHP Getting Random Gives Blank Results

  17. 17

    What is the difference between numpy.random's Generator class and np.random methods?

  18. 18

    Check that string contains a character from array

  19. 19

    Javascript check for 1 special character and 2 digits

  20. 20

    Regex that check if text has the first character equal to @

  21. 21

    Check if String Contains New Line character

  22. 22

    How to not insert duplicate images?

  23. 23

    OpenGL anisotropic filtering support, contradictory check results

  24. 24

    Compiled c++ output file displays random character at end of program?

  25. 25

    How to select a random vector

  26. 26

    How random options in button?

  27. 27

    How to grep and treat meta character as normal character?

  28. 28

    How to type * character in nano?

  29. 29

    MySQL Random Select Query with limit returning different number of results (undesired)

뜨겁다태그

보관