Skip to content

Instantly share code, notes, and snippets.

@edhiley
Last active August 29, 2015 14:24
Show Gist options
  • Save edhiley/bca07ec8926eb5ed0ae1 to your computer and use it in GitHub Desktop.
Save edhiley/bca07ec8926eb5ed0ae1 to your computer and use it in GitHub Desktop.
from random import choice, shuffle
import string
outwardcode_area_choices = ['LS', 'EN', 'BD']
outwardcode_district_choices = xrange(1,20)
inwardcode_sector_choices = string.digits
inwardcode_alphabet = list('ABDEFGHJLNPQRSTUWXYZ')
def gen_postcode():
shuffle(inwardcode_alphabet)
values = {
"outwardcode_area": choice(outwardcode_area_choices),
"outwardcode_district": choice(outwardcode_district_choices),
"inwardcode_sector": choice(inwardcode_sector_choices),
"inwardcode_unit": ''.join(inwardcode_alphabet[:2])
}
output_spec = "{outwardcode_area}{outwardcode_district}" + \
" {inwardcode_sector}{inwardcode_unit}"
return output_spec.format(**values)
# generate one
print gen_postcode()
# generate 100
print '\n'.join([gen_postcode() for _ in xrange(0,100)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment