Re: pgsql: Increase the number of possible random seeds per time period.

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Munro <tmunro(at)postgresql(dot)org>, pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: Re: pgsql: Increase the number of possible random seeds per time period.
Date: 2018-11-15 03:59:15
Message-ID: CAEepm=1hj-r1Bk_x_jkNnssYeZ+FQi2D_2xjJ-oYwjqtL38Wtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Thu, Nov 15, 2018 at 4:38 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Thomas Munro <tmunro(at)postgresql(dot)org> writes:
> > Increase the number of possible random seeds per time period.
>
> Um, this bit is *not* right:
>
> + ((unsigned int) MyStartTimestamp >> 20));
>
> You're cutting it down to 32 bits and then right shifting, which
> means you are shifting in a lot of zeroes when you could be shifting
> in something that's not quite as predetermined. I had in mind to do
> the shifts in uint64 arithmetic and then narrow the final XOR result
> to int (maybe let the compiler do that implicitly).

Will this close the case?

- srandom(((unsigned int) MyProcPid) ^
- ((unsigned int) MyStartTimestamp << 12) ^
- ((unsigned int) MyStartTimestamp >> 20));
+ srandom(((uint64) MyProcPid) ^
+ ((uint64) MyStartTimestamp << 12) ^
+ ((uint64) MyStartTimestamp >> 20));

--
Thomas Munro
http://www.enterprisedb.com

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2018-11-15 04:21:27 Re: pgsql: Increase the number of possible random seeds per time period.
Previous Message Tom Lane 2018-11-15 03:38:35 Re: pgsql: Increase the number of possible random seeds per time period.