Re: Random not so random - Mailing list pgsql-general

From D. Stimits
Subject Re: Random not so random
Date
Msg-id 4162CA17.2090102@comcast.net
Whole thread Raw
In response to Re: Random not so random  (Vivek Khera <khera@kcilink.com>)
List pgsql-general
Vivek Khera wrote:
>>>>>>"DS" == D Stimits <stimits@comcast.net> writes:
>
>
> DS> If it uses the same seed from the connection, then all randoms within
> DS> a connect that has not reconnected will use the same seed. Which means
> DS> the same sequence will be generated each time, which is why it is
> DS> pseudo-random and not random. For it to be random not just the first
> DS> call of a new connection, but among all calls of new connection, it
> DS> would have to seed it based on time at the moment of query and not at
> DS> the moment of connect. A pseudo-random generator using the same seed
> DS> will generate the same sequence.
>
> You clearly demonstrate you do not understand the purpose of a seed in
> a PRNG, nor how PRNG's in general work.  You want to seed it once and
> only once per process, not every time you issue a query.  And nobody
> said to use the same seed every time, either.
>

Sorry, at the time I don't believe PRNG was part of the conversation,
that came after (maybe I missed that). What I saw were functions based
on one-way hashes...is that incorrect? For one-way hashes and
pseudo-random generators using some form of hash a different seed should
be used or else the pattern will be the same when using the same data.
 From the man page on srandom():

        The srandom() function sets its argument as the seed for a new
sequence  of  pseudo-random
        integers  to be returned by random().  These sequences are
repeatable by calling srandom()
        with the same seed value.  If no seed value is provided, the
random() function is automat-
        ically seeded with a value of 1.

The srandom() caught my eye in the earlier email, not PRNG. You are
welcome to re-use srandom() without a new seed if you want.

D. Stimits, stimits AT comcast DOT net

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Verifying Referential Integrity
Next
From: pginfo
Date:
Subject: lower/upper support and cyrillic