How can I generate a (pseudo)random alpha-numeric string, something like: ‘d79jd8c’ in PHP?
How can I generate a (pseudo)random alpha-numeric string, something like: ‘d79jd8c’ in PHP?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First make a string with all your possible characters:
You could also use range() to do this more quickly.
Then, in a loop, choose a random number and use it as the index to the
$charactersstring to get a random character, and append it to your string:$random_string_lengthis the length of the random string.