jeudi 30 juin 2016

How can I generate an random string with exactly length in PHP?

I have a command to generate an random string as :

$random = sprintf('%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535))

But when I test it, sometime they return the string with 10, 11 or 12 length. Anyone can fix this command to always return exactly a string with 12 length (not 10 or 11, etc...). Because of my project, I only can use this command, so please help me fix it and without use a new solution. Thanks all and sorry for my bad English.




Aucun commentaire:

Enregistrer un commentaire