Skip to content

Instantly share code, notes, and snippets.

@fer-ri
Created January 29, 2019 14:37
Show Gist options
  • Save fer-ri/2ee328b9120e64fb7a683396d0f6e5be to your computer and use it in GitHub Desktop.
Save fer-ri/2ee328b9120e64fb7a683396d0f6e5be to your computer and use it in GitHub Desktop.
Generate random readable word by length
<?php
/**
* Generates human-readable string.
*
* @param string $length Desired length of random string.
*
* retuen string Random string.
*/
function readable_random_string($length = 6)
{
$string = '';
$vowels = array("a","e","i","o","u");
$consonants = array(
'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
);
// Seed it
srand((double) microtime() * 1000000);
$max = $length/2;
for ($i = 1; $i <= $max; $i++)
{
$string .= $consonants[rand(0,19)];
$string .= $vowels[rand(0,4)];
}
return $string;
}
var_dump(readable_random_string(10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment