Generate unique random alphanumeric characters that are 7 characters long

前端 未结 15 728
予麋鹿
予麋鹿 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:20

    Here is something that looks random and should be unique and have 7 chars for the times to come:

    echo base_convert(intval(microtime(true) * 10000), 10, 36);
    

    Or for a little more randomness and less uniqueness (between 1000 and 10000 per second):

    echo base_convert(mt_rand(1, 9) . intval(microtime(true) * 1000), 10, 36);
    

    Or (uniqueness between 100 and 10000 per second) - this is probably the best option:

    echo base_convert(mt_rand(10, 99) . intval(microtime(true) * 100), 10, 36);
    

    Or (uniqueness between 10 and 10000 per second):

    echo base_convert(mt_rand(100, 999) . intval(microtime(true) * 10), 10, 36);
    

    You get the idea.

提交回复
热议问题