Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,411
    Thanks
    268
    Thanked 32 Times in 31 Posts

    random names that make sense

    Hi, i have my random alphpnumeric name code done and i thought maybe i might reach into the possibility of taking it to the next level and that is to make it readible (more common) names that make sense.

    Instead of 58lkiu47f i might try to do something like a common name of hank or joe or maybe even a username such as mrtoenail. But im sitting here noodling and went thru google a bit and found some close splitting vowels and consonants but still it might come out rmneonl.

    So i thought ok maybe (might take me an hour or so) to come up with an array of lets say 200 or 300 names and then do rand off of that.

    Just not sure which way i want to go here is all. Any suggestions thanks

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,411
    Thanks
    268
    Thanked 32 Times in 31 Posts
    still rough work and still not quite as readable as i like but here is what i have so far. any input is appreciated.

    PHP Code:

    <?php

    // to select random alphanumeric for readable username.

    $consonants = array("b","c","d","f","g","h","j","k","l","m",
    "n","p","q","r","s","t","v","w","x","y","z");

    $vowels = array("a","e","i","o","u");


    //choose one consonant
    $rand_cons array_rand(array_flip($consonants),1); 

    //for vowels choose 2 
    $rand_vow_store array_rand(array_flip($vowels),2);

    //grab each one from array
    $rand_vowa $rand_vow_store[0];
    $rand_vowb $rand_vow_store[1];

    //now put them together
    $rand_vow $rand_vowa;
    $rand_vow .= $rand_vowb;


    //choose another consonant
    $rand_cons_another array_rand(array_flip($consonants),1); 


    //choose another vowel
    $rand_vow_another array_rand(array_flip($vowels),1);





    /* 

    //was too many so i took this out 

    //pick a random amount of consonants to finish the alpha part

    $rand_amount = rand(2,4);

    $rand_cons_extra = array_rand(array_flip($consonants),$rand_amount); 

    //loop thru and grab them from array
    for ($i=0; $i <= $rand_amount; $i++) 
    {
    $rand_extra_cons .= $rand_cons_extra[$i];
    }//close for

    */


    //for numbers choose random
    $rand_num mt_rand(1,99);  //also took this down to two positions, 4 was too many 



    //at this point your up to 6 min to max 7 chars


    // testing output only 


    echo $rand_cons;
    echo 
    "<br />";
    echo 
    $rand_vow;
    echo 
    "<br />";
    echo 
    $rand_cons_another;
    echo 
    "<br />";
    echo 
    $rand_vow_another;
    //echo $rand_extra_cons;
    echo "<br />";
    echo 
    $rand_num;
    echo 
    "<br />";


    //put it all together

    $finalname $rand_cons;
    $finalname .= $rand_vow;
    $finalname .= $rand_cons_another;
    $finalname .= $rand_vow_another;
    $finalname .= $rand_num;

    echo 
    "finalname = ";
    echo 
    $finalname;


    ?>

    I guess i could seperate the e and the o into its own array so i can at random choose those twice, such as oo and ee for words like geek or wood

    In case your curious, a friend of mine has a social site that some of the special needs people he wanted the ability to do their profile for them and i told him i would see what i could come up with for the random name part.

    UPDATE i have found that grabing one cons and one vowel instead of the rand "extra" cons part of the code works much better. I have edited the code.
    Last edited by durangod; 11-26-2012 at 04:39 AM.

  • #3
    Regular Coder Custard7A's Avatar
    Join Date
    Jul 2010
    Location
    Australia
    Posts
    286
    Thanks
    32
    Thanked 33 Times in 33 Posts
    There are plenty of large text lists you can find with a quick Google search, for dictionary words. You could put those into a text file on your server, with a word per line, and then randomly select two lines from that file via PHP and tack the words together. That would save you formatting them all to an array, at least.

    It would probably have a higher rate (Like, 100%) of readability, than trying to construct a name from singular letters using only a vowel / consonant rule. If it were me, I'd probably want to remove "uninteresting" words from the list as well, or even create some sort of rule along the lines of [adjective] + [noun], or something, for the best results.

  • Users who have thanked Custard7A for this post:

    durangod (11-26-2012)

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,411
    Thanks
    268
    Thanked 32 Times in 31 Posts
    yeah that was one of my original ideas. But this is a freebee, a favor for a friend and i could go all max out on this and still be working on it a week from now.

    Really all they wanted was to be able to have random names. But because i want to do a better job i thought i would venture into making them more readable but to do a really great job at that will take alot more time and time is money ya know.

    So i think they will be happy with this i hope, i was however curious about how to do this should it come up later in life.

    Thanks.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Completely random words that are pronounceable would require analysis of the language itself (not the programming language; the spoken one).
    Language syntax is built on rules. Knowing the rules means you can program the necessary requirements to generate the results. Its not as simple as randomly selecting vowels and constants, there are only certain ways these can be properly combined. That though requires a syntax specialist (for which I certainly am not). These are the same people that would be deeply involved with concocting programming languages themselves as well as interesting applications such as voice control and voice to text (or text to voice). They would *not* come cheap that's for sure.

    Hence the reason why you can find so many word lists online for selection.

  • Users who have thanked Fou-Lu for this post:

    durangod (11-26-2012)

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,411
    Thanks
    268
    Thanked 32 Times in 31 Posts
    This is what i was referring to when i said i would still be at it a week from now lol. Yeah i also did not want to make this a full blown lang interpretation style mod for sure just something that was slightly better than the complete random.

    Thanks Fou-Lu and Custard


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •