How to Win Friends and Generate People

Dice

I’m doing a project for a subject at RMIT which needs to manage thousands of patient records for a hospital. We haven’t been given any sample data though, so I wanted to write a generator (so we can test it with small or large data sets whenever needed).

I started with the name generator (in Python), which selected a random male/female/last name from a file [1]. I then realised an address generator would behave similarly (street, city, country lists), so I decided to make a Generator base class. You can get the source code for these here.

I wanted the Generator base class to create methods dynamically; It would be instantiated with a bunch of methodname-filename pairs and have the methods for randomly selecting an entry from each file made dynamically. Exactly how to do this wasn’t easy to find, as it wasn’t well documented… the solution ended up being:

Niki (my brother) helped me get 70% of the way there… (after lots of scope and decorator issues) thanks man :)

[1] The name lists were taken from this census data, which actually provides percentages for each name too, if you wanted to make the name distribution more realistic…