Skip to content

Instantly share code, notes, and snippets.

@CheeseCake87
Last active April 10, 2025 10:20
Show Gist options
  • Select an option

  • Save CheeseCake87/3707440abbd1dca845de084676a054b5 to your computer and use it in GitHub Desktop.

Select an option

Save CheeseCake87/3707440abbd1dca845de084676a054b5 to your computer and use it in GitHub Desktop.
import random
OFFICIAL_LOCAL_MNEMONICS_LOOKUP = {
"A": "anglia",
"B": "birmingham",
"C": "cymru",
"D": "deeside",
"E": "essex",
"F": "forest_and_fens",
"G": "garden_of_england",
"H": "hampshire_dorset_and_isle_of_white",
"K": "no_official_mnemonic",
"L": "london",
"M": "manchester_and_merseyside",
"N": "newcastle",
"O": "oxford",
"P": "preston",
"R": "reading",
"S": "scotland",
"V": "severn_valley",
"W": "west_of_england",
"X": "personal_export",
"Y": "yorkshire",
}
DVLA_OFFICES = [
("peterborough", "A", "ABCDEFGHIJKMN"),
("norwich", "A", "OPRSTU"),
("ipswich", "A", "VWXY"),
("birmingham", "B", "ABCDEFGHJKLMNOPRSTUVWX"),
("cardiff", "C", "ABCDEFGHJKLMNO"),
("swansea", "C", "PRSTUV"),
("bangor", "C", "WXY"),
("chester", "D", "ABCDEFGHJK"),
("shrewsbury", "D", "LMNOPSTUVWXY"),
("chelmsford", "E", "ABCDEFGHIJKLMNORSTUVWXY"),
("nottingham", "F", "ABCDEFGHJJKLMNP"),
("lincoln", "F", "RSTVWXY"),
("maidstone", "G", "ABCDEFGHJKLMN"),
("brighton", "G", "PRSTUVWXY"),
("bournemouth", "H", "ABCDEFGHJ"),
("Portsmouth", "H", "KLMNPRSTUVXY"),
("luton", "K", "ABCDEFGHJKL"),
("northampton", "K", "MNOPRSTUVWX"),
("wimbledon", "L", "ABCDEFGHJ"),
("stanmore", "L", "KLMNOPRST"),
("sidcup", "L", "UVWXY"),
("manchester", "M", "ABCDEFGHJKLMPTUVWX"),
("newcastle", "N", "ABCDEGHJKLMNO"),
("stockton", "N", "PRSTUVWXY"),
("oxford", "O", "ABCDEFGHJLMOPTUVWX"),
("preston", "P", "ABCDEFGHJKLMNPRST"),
("carlisle", "P", "UVWXY"),
("reading", "R", "ABCDEFGHJKLMNOPRSTVWXY"),
("glasgow", "S", "ABCDEFGHJ"),
("edinburgh", "S", "KLMNO"),
("dundee", "S", "PRST"),
("aberdeen", "S", "VW"),
("inverness", "S", "XY"),
("worcester", "V", "ABCEFGHJKLMNOPRSTUVXY"),
("exeter", "W", "ABDEFGHJ"),
("truro", "W", "KL"),
("bristol", "W", "MNOPRSTUVWX"),
("personal_export", "X", "ABCDEF"),
("leeds", "Y", "ABCDEFGHJKL"),
("sheffield", "Y", "MNOPRSTUV"),
("beverley", "Y", "WXY")
]
def random_dvla_office():
selection = random.choice(DVLA_OFFICES)
_, area, local = selection
return f"{area}{random.choice(local)}"
def random_three_letter():
valid_letters = "ABCDEFGHJKLMNOPRSTUVWXYZ"
return "".join(random.choices(valid_letters, k=3))
def random_vehicle_year():
evens = [f"{str(i)[-2:]}" for i in range(2002, 2026)]
odds = [i for i in range(51, 76)]
return random.choice(evens + odds)
def random_registration():
return f"{random_dvla_office()}{random_vehicle_year()}{random_three_letter()}"
if __name__ == "__main__":
print(random_registration())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment