Generate unique random alphanumeric characters that are 7 characters long

前端 未结 15 726
予麋鹿
予麋鹿 2020-12-09 00:32

It need not be meaningful words - more like random password generation, but the catch is - they should be unique. I will be using this for some kind of package / product cod

相关标签:
15条回答
  • 2020-12-09 01:26
    substr(str_shuffle(md5(microtime())),rand(0,21),7);
    
    0 讨论(0)
  • 2020-12-09 01:28

    Here's a way you could do it without hashes or loops:

    $password = sprintf(
        "%04s%03s",
        base_convert(mt_rand(0, pow(36, 4) - 1), 10, 36),
        base_convert(mt_rand(0, pow(36, 3) - 1), 10, 36)
    );
    

    As a few others have mentioned, ensuring uniqueness is more complicated, and should be unneeded. The simplest way you could do it would be to add extra characters at the end, incrementing with each password generated.

    0 讨论(0)
  • 2020-12-09 01:28
    md5( microtime() );
    
    0 讨论(0)
提交回复
热议问题