Skip to content

Instantly share code, notes, and snippets.

@TwiN
Created January 10, 2016 23:40
Show Gist options
  • Save TwiN/58403e6b349e8bf150fe to your computer and use it in GitHub Desktop.
Save TwiN/58403e6b349e8bf150fe to your computer and use it in GitHub Desktop.
Generates random names and puts them in a .txt file
<?php
//Generates random names and puts them in a txt file
$fileName = 'nameDatabase.txt';
$mode = 2; //MODE 1: array of names || MODE 2: one name per line
$amountOfNames = 100; //Amount of names to be generated
$startTime = microtime(true); //Starts timer
$adjs = array(
'Impressive',
'Overwhelming',
'Crushing',
'Powerful',
'Great',
'Average',
'Special',
'Adorable',
'Confused',
'Impressed',
'Devastating',
'Pathetic',
'Double');
$nouns = array(
'Noob',
'Potato',
'Agent',
'Dragon',
'Sage',
'Soldier',
'Player',
'Wolf',
'Bear');
function generateName() {
global $adjs, $nouns;
$randNum = sprintf('%05d',rand(0,99999));
$name = $adjs[array_rand($adjs)].$nouns[array_rand($nouns)].$randNum;
return $name;
}
if($mode==1) { //This one will make an array of generated name. (between quotes with a ,)
for ($i = 0; $i <= $amountOfNames; $i++) {
$currentUser = generateName();
//echo $currentUser . "\n"; //writes the name in the CLI, but that's optional
file_put_contents($fileName, "'$currentUser', ", FILE_APPEND);
}
}
if($mode==2) { //This will write one generated name per line
for ($i = 0; $i <= $amountOfNames; $i++) {
$currentUser = generateName();
//echo $currentUser . "\n"; //writes the name in the CLI, but that's optional
file_put_contents($fileName, $currentUser . "\n", FILE_APPEND);
}
}
echo "Generated $amountOfNames names in '$fileName' in ". round((microtime(true) - $startTime), 3) ." seconds.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment