[Python-Dev] Weird use of hash() -- will this work?
Thu, 18 Jan 2001 22:56:08 +0100
"Eric S. Raymond" wrote:
> So I'm writing a module to that needs to generate unique cookies. The
> module will run inside one of two environments: (1) a trivial test wrapper,
> not threaded, and (2) a lomg-running multithreaded server.
What do you mean by "unique"? Unique regarding your long-running server?
If so, then I wonder why one should do
> So, how about `time.time()` + hex(hash())?
instead of using a single, simple counter for all sessions?
> It looks to me like this will remain unique forever, because another thread
> would have to create an object at the same memory address during the same
> millisecond to collide.
> Furthermore, it looks to me like this hack might be portable to any OS
> with a clock tick shorter than its timeslice.
If I'm not overlooking something fundamental, the counter approach
seems to be simpler and most portable. :-)
but-sometimes-my-brain-malfunctions-badly-ly y'rs - chris
Christian Tismer :^) <mailto:email@example.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Kaunstr. 26 : *Starship* http://starship.python.net
14163 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
where do you want to jump today? http://www.stackless.com