Re: Random not so random

From: "D(dot) Stimits" <stimits(at)comcast(dot)net>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Random not so random
Date: 2004-10-04 14:22:37
Message-ID: 41615CAD.90009@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> "Arnau Rebassa" <arebassa(at)hotmail(dot)com> writes:
>
>> I'm using a debian linux as OS with a 2.4 kernel running on it.
>
>
>>>Incidentally, are you reconnecting every time or is it that multiple calls
>>>in a single session are returning the same record?
>
>
>> I'm reconnecting each time I want to retrieve a message.
>
>
> Hmm. postmaster.c does this during startup of each backend process:
>
> gettimeofday(&now, &tz);
> srandom((unsigned int) now.tv_usec);

If it uses the same seed from the connection, then all randoms within a
connect that has not reconnected will use the same seed. Which means the
same sequence will be generated each time, which is why it is
pseudo-random and not random. For it to be random not just the first
call of a new connection, but among all calls of new connection, it
would have to seed it based on time at the moment of query and not at
the moment of connect. A pseudo-random generator using the same seed
will generate the same sequence.

D. Stimits, stimits AT comcast DOT net

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew T. O'Connor 2004-10-04 14:50:10 Re: VACUUM FULL on 24/7 server
Previous Message Tom Lane 2004-10-04 14:14:19 Re: Random not so random