Generate unique alphanumeric ID such as in the UK NINO (SN-60-70-45-B) format
<p>How can I generate unique alphanumeric ID such as in the UK NINO (SN-60-70-45-B) format? I want to use this ID to uniquely identify the applications and also to be able to associate these IDs to their medical, tax records and so on.</p>

<p>Assuming the question is for python, start here:
<a href="https://docs.python.org/2/library/uuid.html#module-uuid" rel="nofollow">uuid</a></p>

<p>There is most likely a nicer way to do it but this should help:</p>

<pre><code>import uuid, re
myUID = uuid.uuid1()
myNum = str(myUID.int).replace("-", "")[:6]
myLet = re.sub('\d+', '', str(myUID)).replace("-", "")[:3].upper()
myRes = myLet[:2] + "-" + myNum[:2] + "-" + myNum[2:4] + "-" + myNum[4:6] + "-" + myLet[1:2]
print myRes
</code></pre>

<p>Live Demo:</p>

<p><a href="https://repl.it/DaYP" rel="nofollow">https://repl.it/DaYP</a></p>

python