pgsql: Increase the number of different values used when seeding random

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Increase the number of different values used when seeding random
Date: 2013-10-24 14:03:56
Message-ID: E1VZLW0-0004rZ-2T@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Increase the number of different values used when seeding random().

When a backend process is forked, we initialize the system's random number
generator with srandom(). The seed used is derived from the backend's pid
and the timestamp. However, we only used the microseconds part of the
timestamp, and it was XORed with the pid, so the total range of different
seed values chosen was 0-999999. That's quite limited.

Change the code to also use the seconds part of the timestamp in the seed,
and shift the microseconds so that all 32 bits of the seed are used.

Honza Horak

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/98c50656cac2e6b873419fd09569a9119c02148c

Modified Files
--------------
src/backend/postmaster/postmaster.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-10-25 01:44:20 pgsql: Use improved vsnprintf calling logic in more places.
Previous Message Heikki Linnakangas 2013-10-24 12:42:29 pgsql: Improve documentation of random() function.