473,383 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

unique number generator

Hi,

I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this?

Thanks in advance,

-- Wong

Jul 18 '05 #1
8 4457
On Wed, 19 May 2004 18:36:40 +0800, "Joe Wong" <jo*****@mango.cc>
wrote:
I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this?


Yes. Google for GUID (globally unique identifier) algorithm or UUID
(universally unique algorithm):
"http://www.google.com/search?q=GUID+algorithm",
"http://www.google.com/search?q=UUID+algorithm".

If you need to use one, instead of implement one, and
you're running on Windows machines with Mark Hammond's
win32 extensions, you can do it easily:

import pywintypes
guid = pywintypes.CreateGuid()
have_a_nice_day(guid)

--dang
Jul 18 '05 #2
"Joe Wong" <jo*****@mango.cc> wrote in message news:<ma************************************@pytho n.org>...
Hi,

I need to implement a unique number generator that 1 or more processes
on same or different machines will make use of it. Is there any library
/ project available already for this?


Try:
http://egenix.com/files/python/mxUID.html
or
http://www.alcyone.com/software/uid/
Jul 18 '05 #3
Hi,

There is a constraint that the number can be at most 8 digits, ie:

00000000 ~ 99999999

No hex decimal is allowed...

And I am on Linux platform..

Any other suggestion? :-)
----- Original Message -----
From: "Daniel 'Dang' Griffith" <no*****@noemail4u.com>
Newsgroups: comp.lang.python
To: <py*********@python.org>
Sent: Wednesday, May 19, 2004 9:06 PM
Subject: Re: unique number generator

On Wed, 19 May 2004 18:36:40 +0800, "Joe Wong" <jo*****@mango.cc>
wrote:
I need to implement a unique number generator that 1 or more processes
on same or different machines will make use of it. Is there any library /
project available already for this?
Yes. Google for GUID (globally unique identifier) algorithm or UUID
(universally unique algorithm):
"http://www.google.com/search?q=GUID+algorithm",
"http://www.google.com/search?q=UUID+algorithm".

If you need to use one, instead of implement one, and
you're running on Windows machines with Mark Hammond's
win32 extensions, you can do it easily:

import pywintypes
guid = pywintypes.CreateGuid()
have_a_nice_day(guid)

--dang
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4
Daniel 'Dang' Griffith <no*****@noemail4u.com> writes:
On Wed, 19 May 2004 18:36:40 +0800, "Joe Wong" <jo*****@mango.cc>
wrote:
I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this?


Yes. Google for GUID (globally unique identifier) algorithm or UUID
(universally unique algorithm):
"http://www.google.com/search?q=GUID+algorithm",
"http://www.google.com/search?q=UUID+algorithm".

If you need to use one, instead of implement one, and
you're running on Windows machines with Mark Hammond's
win32 extensions, you can do it easily:

import pywintypes
guid = pywintypes.CreateGuid()
have_a_nice_day(guid)

--dang


Pyro.util.getGUID() is a cross-platform solution. Or, you can write a
wrapper which uses MS's guid on Win** platforms, and Pyro's on *NIX
platforms.

--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #5
"Joe Wong" <jo*****@mango.cc> writes:
Hi,

There is a constraint that the number can be at most 8 digits, ie:

00000000 ~ 99999999

No hex decimal is allowed...

And I am on Linux platform..

Any other suggestion? :-)


I hope you get to control all the generators for this number.
Otherwise different algorithms may accidentally overlap even if they
are properly unique in their own streams.

Given that, you need a unique number up to 1e9.

1. If you can get the traditional GUID based on MAC+timestamp+random,
you might hash that down to a digital signature in your number
range. This increases the possibility of overlaps, but it might be
acceptable in your context. E.g., do an md5 on your guid and take
the lower 7 hex digits.

2. If there are characteristics of the problem space which are
themselves unique, then you might do a canonical mapping from that
to integers. If you are lucky, this could be a dense mapping (no
skipped integers), and thus able to support a billion unique items.
--
ha************@boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #6
"Joe Wong" <jo*****@mango.cc> writes:
There is a constraint that the number can be at most 8 digits, ie:
00000000 ~ 99999999


What an odd constraint. Is this your homework?

Your best bet is to issue increasing serial numbers from a process
that's properly mulithreaded and persistent. If you're really lazy,
install MySQL and have it generate unique IDs for you.
Jul 18 '05 #7
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

Jul 18 '05 #8
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" <je****@unpythonic.net>
To: "Joe Wong" <jo*****@mango.cc>
Cc: "Daniel 'Dang' Griffith" <no*****@noemail4u.com>;
<py*********@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

Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
4
by: RCS | last post by:
We have sort of a centralized single-signon written in ASP.NET for all of our legacy ASP and ASP.NET apps.. There are around 1200 users and something like 2 dozen apps. Everyonce in a while, a user...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
3
by: Nel | last post by:
From your (group) opinion, when sending a unique URL to a user, what steps are a must in making sure the link can't be hacked. i.e. Bad link www.example.com?id=10&action=reset_password ...
15
by: A. Farber | last post by:
Hello, I'm programming a web game on OpenBSD, but am also trying to keep in runnable on Linux and Cygwin. I have a list of tables at which a player/kibitzer can sit down or create a new empty...
16
by: Mark S. | last post by:
I'm a fan of the GUID, but the current project is looking to use a genuinely unique integer. Does the following do that? Math.Abs(System.Guid.NewGuid().GetHashCode()) TIA
20
by: A | last post by:
Hi all. Is this a bug or what??? here is a simple code: <?php mt_srand(1); echo mt_rand(0, 255)."<br />"; echo mt_rand(0, 255)."<br />";
6
by: er | last post by:
hi, here's why i'm trying to do: header1.hpp namespace{ struct A{};} struct B1{ A a; }; header2.hpp namespace{ struct A{};}
8
by: remlostime | last post by:
i use g++ to generater rand number, now i find that the RAND_MAX is 32367 in my computer, how can i make a bigger rand number( the number is wihin in the integer(2^32-1))
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.