---- Message from  mailto:m...@sai.msu.ru "Sergey E. Koposov"  m...@sai.msu.ru 
at 05-04-2010 06:36:23 PM ------

Hello,

I'm getting strange results with PostgreSQL random() function. It would  be
great if someone could either show where I am wrong or PG is wrong. Here
is what I do (PG 8.4.3, x86_64 platform);

I basically try to create the table with the column filled with random
numbers (either integer or doubles). And I'm getting too many  collisions.

Here is the SQL code:
-----------------------

begin;
select setseed(0);
create temporary table tmpx1 as select ((random())) as id from
generate_series(1,100000);
select id ,count(*) from tmpx1 group by (id) having count(*)1;


***snip**
Random() does not guarantee the results will not repeat. its just like rolling 
dice every time the dice rolls its an independent result so it will repeat at 
some point, so every time Random() is called its an independent event that has 
no idea about past results. You are calling random 100,000 times.

To create a random list of numbers that don't repeat you have to filter the 
repeated values out one at a time, with another function.

Tip trying to use sql to filter out duplicated values will sort the result set 
first before filtering duplicates resulting in a not so random list of numbers.







All legitimate Magwerks Corporation quotations are sent in a .PDF file 
attachment with a unique ID number generated by our proprietary quotation 
system. Quotations received via any other form of communication will not be 
honored.

CONFIDENTIALITY NOTICE: This e-mail, including attachments, may contain legally 
privileged, confidential or other information proprietary to Magwerks 
Corporation and is intended solely for the use of the individual to whom it 
addresses. If the reader of this e-mail is not the intended recipient or 
authorized agent, the reader is hereby notified that any unauthorized viewing, 
dissemination, distribution or copying of this e-mail is strictly prohibited. 
If you have received this e-mail in error, please notify the sender by replying 
to this message and destroy all occurrences of this e-mail immediately.
Thank you.

Reply via email to