How to generate account number?

Andriy Kornatskyy andriy.kornatskyy at live.com
Sat Nov 3 12:18:09 EDT 2012


Roy,

Per your advise:

>>> from base64 import b32encode
>>> human_format = lambda n: 'Z%s-%s' % (b32encode(chr((n >> 24) & 255) + chr((n >> 16) & 255))[:4], b32encode(chr((n >> 8) & 255) + chr(n & 255))[:4])
>>> human_format(5738521581)
'ZKYFA-4PWQ'
>>> human_format(17888279480)
'ZFI4Q-PO4A'
>>> human_format(7395350007)
'ZXDGA-CX3Q'

Side by side:

Z05738521581 = ZKYFA-4PWQ
Z17888279480 = ZFI4Q-PO4A
Z07395350007 = ZXDGA-CX3Q

Thanks.

Andriy


----------------------------------------
> From: roy at panix.com
> Subject: Re: How to generate account number?
> Date: Sat, 3 Nov 2012 09:22:55 -0400
> To: python-list at python.org
>
> In article <mailman.3234.1351931985.27098.python-list at python.org>,
> Andriy Kornatskyy <andriy.kornatskyy at live.com> wrote:
>
> > 'Z05738521581'
> > 'Z17888279480'
> > 'Z07395350007'
> >
> > Short, human readable and satisfy original requirements.
> >
> > Andriy
>
> If you really want human readable, it's better to chunk the data up into
> 3 or 4 digit groups. So, instead of Z05738521581, maybe
> Z05-738-521-581. Or perhaps even better, Z05-7385-21-581 (just a hunch,
> but I suspect varying the length of the groups makes it easier to read).
>
> Even better might be base-32 encoding the value. Strings of digits have
> an information density of about 3.2 bits/char. Base-32 is just about as
> readable, but gives you 5 bits/char, so you end up with a few less
> characters (which you still want to chunk into 3 or 4 character groups).
> --
> http://mail.python.org/mailman/listinfo/python-list
 		 	   		  


More information about the Python-list mailing list