Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHP generate random string with characters [0-9a-f].
<?php
function generateRandString() {
$randString = '';
while (strlen($randString) < 32) {
// generate a character between 0-9 a-f
$character = mt_rand(0,15);
if ($character > 9) $character += 39;
$randString .= chr($character + 48);
}
return $randString;
}
echo(generateRandString());
// something like: d31c982325d93030124d515208d2a3a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.