This blog is for generating names, based on the frequency they occur. It can be easily adjusted for any country if you have similar data.

It’s generating the names based on the statistics how often they occur in the USA, based on data from United State Census Bureau. Using this approach makes the generated data to look more real, than just randomizing the first and last name from an array.

The code is available in GitHub:

The usage is straight forward:

string firstFemaleName = NameGenerator.GetRandomFirstFemaleName();
string firstMaleName = NameGenerator.GetRandomFirstMaleName();
string firstName = NameGenerator.GetRandomFirstName();
string lastName = NameGenerator.GetRandomLastName();
string fullName = NameGenerator.GetRandomFullName();

If you want to change the code to work for another country you just need to replace the data files.

Each of the three files, (dist.all.last), (dist. male.first), and (dist female.first) contain four items of data. The four items are:

  1. A “Name”
  2. Frequency in percent
  3. Cumulative Frequency in percent
  4. Rank

Let me know if you have any questions or comments on how I can improve the blog and/or the source code.


Categories: Quick tipsTesting

Leave a Reply

Your email address will not be published. Required fields are marked *