Thanks anyone in advance for answering/attempting to answer my question.
I'm currently using a php script to generate random string, but now I'd like to generate random name of a person instead of generating just a random string. My old code looked something like this:
<?php
function RandomString($length) {
$keys = array_merge(range('a', 'z'), range('A', 'Z'));
for($i=0; $i < $length; $i++) {
$key .= $keys[array_rand($keys)];
}
return $key;
}
print RandomString(6);
?>
Thanks Again in Advance.
php function RandomString($length) { $keys = array_merge(range('a', 'z'), range('A', 'Z')); for($i=0; $i < $length; $i++) { $key . = $keys[array_rand($keys)]; } return $key; } print RandomString(6); ?>
Names are just the beginning! Check out Faker:
<?php
require_once '/path/to/Faker/src/autoload.php';
$faker = Faker\Factory::create();
echo $faker->name;
echo $faker->phoneNumber;
echo $faker->paragraph(2);
This might produce the following output...different every time:
John Smith
800-867-5309
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Donec quam
felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla
consequat massa quis enim. Donec pede justo, fringilla vel, aliquet
nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a,
venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.
Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean
vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat
vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra
quis, feugiat a, tellus.
More info here: https://github.com/fzaninotto/Faker
I found this question because I needed the same thing. For anyone else looking, this is a function for 50 first names paired with 50 surnames giving 2500 possibilities. It's based on the accepted answer and the the random names are courtesy of http://listofrandomnames.com
echo randomName();
function randomName() {
$firstname = array(
'Johnathon',
'Anthony',
'Erasmo',
'Raleigh',
'Nancie',
'Tama',
'Camellia',
'Augustine',
'Christeen',
'Luz',
'Diego',
'Lyndia',
'Thomas',
'Georgianna',
'Leigha',
'Alejandro',
'Marquis',
'Joan',
'Stephania',
'Elroy',
'Zonia',
'Buffy',
'Sharie',
'Blythe',
'Gaylene',
'Elida',
'Randy',
'Margarete',
'Margarett',
'Dion',
'Tomi',
'Arden',
'Clora',
'Laine',
'Becki',
'Margherita',
'Bong',
'Jeanice',
'Qiana',
'Lawanda',
'Rebecka',
'Maribel',
'Tami',
'Yuri',
'Michele',
'Rubi',
'Larisa',
'Lloyd',
'Tyisha',
'Samatha',
);
$lastname = array(
'Mischke',
'Serna',
'Pingree',
'Mcnaught',
'Pepper',
'Schildgen',
'Mongold',
'Wrona',
'Geddes',
'Lanz',
'Fetzer',
'Schroeder',
'Block',
'Mayoral',
'Fleishman',
'Roberie',
'Latson',
'Lupo',
'Motsinger',
'Drews',
'Coby',
'Redner',
'Culton',
'Howe',
'Stoval',
'Michaud',
'Mote',
'Menjivar',
'Wiers',
'Paris',
'Grisby',
'Noren',
'Damron',
'Kazmierczak',
'Haslett',
'Guillemette',
'Buresh',
'Center',
'Kucera',
'Catt',
'Badon',
'Grumbles',
'Antes',
'Byron',
'Volkman',
'Klemp',
'Pekar',
'Pecora',
'Schewe',
'Ramage',
);
$name = $firstname[rand ( 0 , count($firstname) -1)];
$name .= ' ';
$name .= $lastname[rand ( 0 , count($lastname) -1)];
return $name;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With