Search Postgresql Archives

Re: How to generate unique hash-type id?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday 29 January 2010 12.51:20 Joe Kramer wrote:
> So this means random()+random() is not random even within 2,000,000
>  iterations!
> 

Exactly the issue I wrote about: random() apparently doesn't deliver enough 
randomness.

Even if it did: quote_literal(random() + random()) is ca. 14 to 16 decimals, 
so this gets you ca. 40 to 50 bits of randomness (again: assuming random() 
actually can produce it!  You'll really have to look into the implementation 
of random() for all your supported versions of pg and platforms!)

So, of the 160 bit that are possible for a sha1 hash, your're only using 25% 
(and that's 25% of the bits.  That means you're only using 1e12 of the 
1.4e48 possible values. which is about 
0.000000000000000000000000000000000001% if my math isn't totally bogus.

(Read up about the birthday paradoxon to get an idea on how likely a 
collision is depending on how long your random number is.)

cheers
-- vbi

-- 
featured link: http://www.pool.ntp.org

Attachment: signature.asc
Description: This is a digitally signed message part.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux