unique number generator

Joe Wong joewong at mango.cc
Wed May 19 21:31:31 EDT 2004


Hi,

 Thanks for all your people input here, I have learnt a lot besides the
solution itself but also the way to analyze my problem here. :-)

Best regards,

-- Wong

----- Original Message ----- 
From: "Jeff Epler" <jepler at unpythonic.net>
To: "Joe Wong" <joewong at mango.cc>
Cc: "Daniel 'Dang' Griffith" <noemail at noemail4u.com>;
<python-list at python.org>
Sent: Thursday, May 20, 2004 12:28 AM
Subject: Re: unique number generator


> This is probably not easy to do, without more requirements.
>
> UUIDs can be generated randomly, in which case about 120 of the 128 bits
> may vary.  This means that you wouldn't expect to generate two that are
> identical before about 2^60 are generated, which is enough to make most
> people comfortable.
>
> 8-digit numbers, well, they're shorter.  You'd expect to have a
> collision after about 10,000 "unique" numbers are generated randomly.
> This isn't very many!
>
> UUIDs can be generated using partly a number which should be unique to
> each machine, plus some other factors.  You could consider doing this,
> giving each machine a unique prefix and generating the suffixes randomly
> or sequentially.  For example, if you have 100 of fewer hosts, you give
> them the 2-digit prefixes 00 through 99, and let them generate IDs by
> choosing the final 6 digits.  If the machine does so randomly, you'll
> expect a collision after about sqrt(10e6) ~ 3000 IDs per machine, and
> if it is done sequentially on each machine then you can use all 10e6 IDs
> on each machine.  3000 and 10e6 are both pretty small, though.
>
> There's a reason that UUIDs are large numbers, unless your system is
> guaranteed to be very small, narrow "unique numbers" will fail, and if
> your system is small you might as well allocate them manually, or
> automatically but sequentially from some "master" source.
>
> Jeff
>





More information about the Python-list mailing list