Generating unique numbers?

Ken Seehof kseehof at neuralintegrator.com
Fri May 31 17:53:44 EDT 2002


> Is there a good algorithm for generating unique numbers 
> (ints, specifically) that can be used as object identifiers?
> 
> I am discounding the obvious newid += 1 because I will need 
> to merge different sets, and while I may have some number 
> overlap, using a simple count for each object would 
> guarantee that I have the maximum number of clashes.
> 
> Specifically, I will be using these numbers as dictionary keys.
> 
> Thanks,
> 
> VanL

I don't know your exact situation, but it sounds like you
can use

  my_dict[id(obj)] = obj

I use this pattern frequently to represent object sets.

- Ken Seehof







More information about the Python-list mailing list