Unique S/N Generator?
devicerandom
devicerandom at gmail.com
Mon Feb 7 17:19:11 UTC 2011
On 07/02/11 17:01, Amichai Rotman wrote:
> Hello,
>
> I would like to hand out some Coupons to my customers granting the 2-3
> hours free phone support as part of a marketing campaign.
>
> I am looking for a way to generate a unique S/N number / code
> (preferably letters and numbers) for them to read back to me over the
> phone, so I can verify it's authenticity and provide them the service.
>
> Is there a tool out there I can use?
With a bit of Python you can go anywhere. This code *should* generate
10000 unique alphanumeric codes and save them to a text file (I haven't
tested it).
#!/usr/bin/env python
import random
a='1234567890abcdefghi' #we return permutations of this string
a = list(a)
codes=[]
for i in range(10000): #we generate 10000 codes
code = ''.join(random.shuffle(a)))
if not (code in codes): #avoid duplicates -very improbable but cheap
codes.append(code)
f = open('codes.txt','w')
f.write('\n'.join(codes))
f.close()
> I'd like to set different ranges of codes for different target audiences.
This is easy -just include a unique character for each target audience
in the initial string.
http://docs.python.org/library/random.html can help.
cheers,
m.
--
http://devicerandom.org
More information about the ubuntu-users
mailing list