/2013/02/random-name-generator/index.html
HTML | 330 lines | 204 code | 122 blank | 4 comment | 0 complexity | b75a692655c0e4496a9d1d2c53cb51e0 MD5 | raw file
- <!DOCTYPE html>
- <!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
- <!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
- <!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
- <head>
- <meta charset="utf-8">
- <title>Random Name Generator in Python - Trey Hunner</title>
- <meta name="author" content="Trey Hunner">
-
- <meta name="description" content="I’ve used multiple websites to generate random names for my test data when
- running manual or automated QA tests. Since discovering DuckDuckGo& …">
-
- <!-- http://t.co/dKP3o1e -->
- <meta name="HandheldFriendly" content="True">
- <meta name="MobileOptimized" content="320">
- <meta name="viewport" content="width=device-width, initial-scale=1">
-
- <link rel="canonical" href="http://treyhunner.com/2013/02/random-name-generator">
- <link href="/favicon.png" rel="icon">
- <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
- <link href="/atom.xml" rel="alternate" title="Trey Hunner" type="application/atom+xml">
- <script src="/javascripts/modernizr-2.0.js"></script>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/libs/jquery.min.js"%3E%3C/script%3E'))</script>
- <script src="/javascripts/octopress.js" type="text/javascript"></script>
- <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
- <link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
- <link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
-
- <script type="text/javascript">
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-26977066-1']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- </script>
- </head>
- <body >
- <header role="banner"><hgroup>
- <h1><a href="/">Trey Hunner</a></h1>
-
- <h2>web development, programming, open source</h2>
-
- </hgroup>
- </header>
- <nav role="navigation"><ul class="subscription" data-subscription="rss">
- <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
-
- </ul>
-
- <form action="http://google.com/search" method="get">
- <fieldset role="search">
- <input type="hidden" name="q" value="site:treyhunner.com" />
- <input class="search" type="text" name="q" results="0" placeholder="Search"/>
- </fieldset>
- </form>
-
- <ul class="main-navigation">
- <li><a href="/">Blog</a></li>
- <li><a href="/blog/archives">Archives</a></li>
- <li><a href="/talks">Talks</a></li>
- <li><a href="/projects">Projects</a></li>
- <li><a href="/about">About</a></li>
- </ul>
- </nav>
- <div id="main">
- <div id="content">
- <div>
- <article class="hentry" role="article">
-
- <header>
-
- <h1 class="entry-title">Random Name Generator in Python</h1>
-
-
- <p class="meta">
-
-
- <time datetime="2013-02-17T00:00:00-08:00" pubdate data-updated="true"></time>
-
- | <a href="#disqus_thread"
- data-disqus-identifier="http://treyhunner.com">Comments</a>
-
- </p>
-
- </header>
- <div class="entry-content"><p>I’ve used multiple websites to generate random names for my test data when
- running manual or automated QA tests.</p>
- <p>Since discovering DuckDuckGo’s <a href="https://duckduckgo.com/?q=random+word">random word</a> generation, I’ve
- <a href="https://duckduckhack.uservoice.com/forums/5168-ideas-for-duckduckgo-instant-answer-plugins/suggestions/2850418-random-name">hoped</a> that someone would make a DuckDuckGo plugin to generate
- random names also.</p>
- <p>I didn’t want to write my own DuckDuckGo plugin yet so I made a Python-powered
- command line tool instead using <a href="https://www.census.gov/genealogy/www/data/1990surnames/index.html">1990 Census data</a>.</p>
- <p>The program is called <code>names</code> and can be found on <a href="https://github.com/treyhunner/names">Github</a> and <a href="http://pypi.python.org/pypi/names/0.1">PyPI</a>.</p>
- <h3>It’s really simple</h3>
- <p>It’s basically just one file currently that’s <a href="https://github.com/treyhunner/names/blob/f99542dc21f48aa82da4406f8ce408e92639430d/names/__init__.py">about 40 lines long</a>.
- There is only one feature available from the command line currently: generate a
- single random full name. There’s a few more features if importing as a Python
- package: generate random last name or generate random first name (with or
- without specifying gender), generate random full name (also without or without
- gender).</p>
- <p>The random name picker relies on the cumulative frequencies listed in the
- included Census data files. Here’s the steps that are taken:
- 1. A random floating point number is chosen between 0.0 and 90.0
- 2. Name file lines are iterated through until a cumulative frequency is found
- that is less than the randomly generated number
- 3. The name on that line is chosen and returned (or printed out)</p>
- <h3>Examples</h3>
- <p>Here’s how you use it from the command line:</p>
- <pre><code>$ names
- Kara Lopes
- </code></pre>
- <p>Here’s how you use it as a Python package:</p>
- <pre><code>>>> import names
- >>> names.get_full_name()
- u'Patricia Halford'
- >>> names.get_full_name(gender='male')
- u'Patrick Keating'
- >>> names.get_first_name()
- 'Bernard'
- >>> names.get_first_name(gender='female')
- 'Christina'
- >>> names.get_last_name()
- 'Szczepanek'
- </code></pre>
- </div>
- <footer>
- <p class="meta">
-
-
- <span class="byline author vcard">Posted by <span class="fn">Trey Hunner</span></span>
-
-
- <time datetime="2013-02-17T00:00:00-08:00" pubdate data-updated="true"></time>
-
- </p>
-
- <div class="sharing">
-
- <a href="//twitter.com/share" class="twitter-share-button" data-url="http://treyhunner.com/2013/02/random-name-generator/" data-via="" data-counturl="http://treyhunner.com/2013/02/random-name-generator/" >Tweet</a>
-
-
- <div class="g-plusone" data-size="medium"></div>
-
-
- </div>
-
- <p class="meta">
-
- <a class="basic-alignment left" href="/2012/12/tmuxstart/" title="Previous Post: tmuxstart">« tmuxstart</a>
-
-
- <a class="basic-alignment right" href="/2013/03/pseudorandom.name/" title="Next Post: Random name generator website">Random name generator website »</a>
-
- </p>
- </footer>
- </article>
- </div>
- <aside class="sidebar">
-
- <section>
- <h1>Recent Posts</h1>
- <ul id="recent_posts">
-
- <li class="post">
- <a href="/2014/05/cli-for-finding-drm-free-audiobooks/">CLI for Finding DRM-free Audiobooks</a>
- </li>
-
- <li class="post">
- <a href="/2014/03/migrating-to-django-1-dot-7/">Supporting Both Django 1.7 and South</a>
- </li>
-
- <li class="post">
- <a href="/2013/11/tdd-with-django-workshop/">TDD With Django Tutorial</a>
- </li>
-
- <li class="post">
- <a href="/2013/10/visual-integration-tests-for-django/">Visual Integration Tests for Django</a>
- </li>
-
- </ul>
- </section>
- <section class="aboutme">
- <script src="//about.me/embed/treyhunner?image=0&headline=0&bio=0&style=site"></script>
- </section>
- <section>
- <h1>GitHub Repos</h1>
- <ul id="gh_repos">
- <li class="loading">Status updating...</li>
- </ul>
-
- <a href="https://github.com/treyhunner">@treyhunner</a> on GitHub
-
- <script type="text/javascript">
- $(document).ready(function(){
- if (!window.jXHR){
- var jxhr = document.createElement('script');
- jxhr.type = 'text/javascript';
- jxhr.src = '/javascripts/libs/jXHR.js';
- var s = document.getElementsByTagName('script')[0];
- s.parentNode.insertBefore(jxhr, s);
- }
- github.showRepos({
- user: 'treyhunner',
- count: 4,
- skip_forks: false,
- target: '#gh_repos'
- });
- });
- </script>
- <script src="/javascripts/github.js" type="text/javascript"> </script>
- </section>
-
- </aside>
- </div>
- </div>
- <footer role="contentinfo"><p>
- Copyright © 2014 - Trey Hunner -
- <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
- </p>
- </footer>
-
- <script type="text/javascript">
- var disqus_shortname = 'treyhunner';
-
-
- var disqus_script = 'count.js';
-
- (function () {
- var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
- dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
- }());
- </script>
- <script type="text/javascript">
- (function() {
- var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
- script.src = 'https://apis.google.com/js/plusone.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
- })();
- </script>
- <script type="text/javascript">
- (function(){
- var twitterWidgets = document.createElement('script');
- twitterWidgets.type = 'text/javascript';
- twitterWidgets.async = true;
- twitterWidgets.src = '//platform.twitter.com/widgets.js';
- document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
- })();
- </script>
- </body>
- </html>