# Random name generator!

**URL:** <https://www.ruby-forum.com/t/random-name-generator/134451>\
**Category:** Ruby\
**Created:** [April 10, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/random-name-generator/134451 "2008-04-10T23:40:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![probability](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@probability](https://www.ruby-forum.com/u/probability)\
**Post date:** [April 10, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/random-name-generator/134451/1 "2008-04-10T23:40:15Z")

</div>

Hello to all;

I’m testing out different ways to output randomly generated names. I’ve  
toyed with some basic algorithms but recently I’ve become hooked on the  
idea of using a Markov chain in the process to generate names based on a  
text file. Below is a link to my first effort - I won’t even begin to  
start on what a catastrophe it is and I don’t expect you to understand  
it:

[http://pastie.textmate.org/178820](http://pastie.textmate.org/178820)

It’s hideous. I’m never going near it again. It basically looks at each  
line of a text file and throws the adjacent letter pairings into a big  
hash with probability weightings, moves through the probability hash  
coughing out likely letter results based on the previous entry. I think  
the term for it is “first-order Markov chain”.

What I’d like to see if anyone has any suggestions, or more importantly  
examples of how this should be done? I’m fairly certain there are more  
elegant ways about doing this. Thanks.

---

<div class="post-metadata">

**Author:** ![probability](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@probability](https://www.ruby-forum.com/u/probability)\
**Post date:** [April 11, 2008, 11:47am UTC](https://www.ruby-forum.com/t/random-name-generator/134451/2 "2008-04-11T11:47:18Z")

</div>

I would suggest using combinations of phonemes rather than letters. It  
would simplify the problem and generate more natural sounding  
combinations.

---

<div class="post-metadata">

**Author:** ![probability](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@probability](https://www.ruby-forum.com/u/probability)\
**Post date:** [April 11, 2008, 2:12am UTC](https://www.ruby-forum.com/t/random-name-generator/134451/3 "2008-04-11T02:12:24Z")

</div>

On Thu, 10 Apr 2008 16:40:17 -0500, Dss Jss wrote:

> It’s hideous. I’m never going near it again. It basically looks at each  
> line of a text file and throws the adjacent letter pairings into a big  
> hash with probability weightings, moves through the probability hash  
> coughing out likely letter results based on the previous entry. I think  
> the term for it is “first-order Markov chain”.
> 
> What I’d like to see if anyone has any suggestions, or more importantly  
> examples of how this should be done? I’m fairly certain there are more  
> elegant ways about doing this. Thanks.

[http://rubyquiz.com/quiz74.html](http://rubyquiz.com/quiz74.html)

The solutions are for word markov chains, but you could easily adapt any  
of them for letter markov chains.

–Ken

---

<div class="post-metadata">

**Author:** ![probability](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@probability](https://www.ruby-forum.com/u/probability)\
**Post date:** [April 11, 2008, 11:11pm UTC](https://www.ruby-forum.com/t/random-name-generator/134451/4 "2008-04-11T23:11:00Z")

</div>

On Fri, 11 Apr 2008 04:47:20 -0500, Sean Mehonoshen wrote:

> I would suggest using combinations of phonemes rather than letters. It  
> would simplify the problem and generate more natural sounding  
> combinations.

Too hard, because then you have to specify what they are. Use a higher- order markov model (like 4 or 5), and you'll get pronouncable results.

One of my colleagues wrote [Linguistic Cognition Laboratory: About](http://lingcog.iit.edu/~scubed/cgi-bin/)  
gibberish.sh, which is a 4th-order markov model of English letters. It  
shoudl be relatively pronouncable, and might suit your needs.
