pgsql: Increase the number of different values used when seeding random - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Increase the number of different values used when seeding random
Date
Msg-id E1VZLW0-0004rZ-2T@gemulon.postgresql.org
Whole thread Raw
List 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(-)


pgsql-committers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: pgsql: Improve documentation of random() function.
Next
From: Tom Lane
Date:
Subject: pgsql: Use improved vsnprintf calling logic in more places.