Thread

Commits

  1. Doc: update description of random() function.

  2. Replace random(), pg_erand48(), etc with a better PRNG API and algorithm.

  1. random() function documentation

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2022-04-11T18:38:45Z

    Hi Hackers,
    
    I just noticed that the since the random() rewrite¹, the documentation's
    claim² that it "uses a simple linear congruential algorithm" is no
    longer accurate (xoroshiro128** is an xorshift variant, which is a
    linear-feedback shift register algorithm).
    
    I don't have a suggestion for the exact wording, since I don't know
    whether xoroshiro128** qualifies as "simple", or to what level of
    specificity we want to document the algorithm.
    
    - ilmari
    
    [1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=3804539e48e794781c6145c7f988f5d507418fa8
    [2] https://www.postgresql.org/docs/devel/functions-math.html#FUNCTIONS-MATH-RANDOM-TABLE
    
    
    
    
  2. Re: random() function documentation

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-04-11T18:45:19Z

    =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
    > I just noticed that the since the random() rewrite¹, the documentation's
    > claim² that it "uses a simple linear congruential algorithm" is no
    > longer accurate (xoroshiro128** is an xorshift variant, which is a
    > linear-feedback shift register algorithm).
    
    > I don't have a suggestion for the exact wording, since I don't know
    > whether xoroshiro128** qualifies as "simple", or to what level of
    > specificity we want to document the algorithm.
    
    How about we just say "uses a linear-feedback shift register algorithm"?
    "Simple" is in the eye of the beholder anyway.
    
    			regards, tom lane
    
    
    
    
  3. Re: random() function documentation

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2022-04-11T19:00:26Z

    Tom Lane <tgl@sss.pgh.pa.us> writes:
    
    > =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
    >> I just noticed that the since the random() rewrite¹, the documentation's
    >> claim² that it "uses a simple linear congruential algorithm" is no
    >> longer accurate (xoroshiro128** is an xorshift variant, which is a
    >> linear-feedback shift register algorithm).
    >
    >> I don't have a suggestion for the exact wording, since I don't know
    >> whether xoroshiro128** qualifies as "simple", or to what level of
    >> specificity we want to document the algorithm.
    >
    > How about we just say "uses a linear-feedback shift register algorithm"?
    
    That works for me.  Nice and simple, and not overly specific.  Should we
    perhaps also add a warning that the same seed is not guaranteed to
    produce the same sequence across different (major?) versions?
    
    > "Simple" is in the eye of the beholder anyway.
    
    Indeed.
    
    > 			regards, tom lane
    
    - ilmari
    
    
    
    
  4. Re: random() function documentation

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-04-11T19:19:47Z

    =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
    > Tom Lane <tgl@sss.pgh.pa.us> writes:
    >> How about we just say "uses a linear-feedback shift register algorithm"?
    
    > That works for me.  Nice and simple, and not overly specific.  Should we
    > perhaps also add a warning that the same seed is not guaranteed to
    > produce the same sequence across different (major?) versions?
    
    I wouldn't bother, on the grounds that then we'd need such disclaimers
    in a whole lot of places.  Others might see it differently though.
    
    			regards, tom lane
    
    
    
    
  5. Re: random() function documentation

    Dean Rasheed <dean.a.rasheed@gmail.com> — 2022-04-12T00:18:58Z

    On Mon, 11 Apr 2022 at 20:20, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >
    > >> How about we just say "uses a linear-feedback shift register algorithm"?
    
    I think it'd be sufficient to just say that it's a deterministic
    pseudorandom number generator. I don't see much value in documenting
    the internal algorithm used.
    
    > > Should we
    > > perhaps also add a warning that the same seed is not guaranteed to
    > > produce the same sequence across different (major?) versions?
    >
    > I wouldn't bother, on the grounds that then we'd need such disclaimers
    > in a whole lot of places.  Others might see it differently though.
    
    Agreed, though I think when the release notes are written, they ought
    to warn that the sequence will change with this release.
    
    Regards,
    Dean
    
    
    
    
  6. Re: random() function documentation

    Fabien COELHO <coelho@cri.ensmp.fr> — 2022-04-12T08:19:07Z

    >>>> How about we just say "uses a linear-feedback shift register algorithm"?
    >
    > I think it'd be sufficient to just say that it's a deterministic
    > pseudorandom number generator. I don't see much value in documenting
    > the internal algorithm used.
    
    Hmmm… I'm not so sure. ISTM that people interested in using the random 
    user-facing variants (only random?) could like a pointer on the algorithm 
    to check for the expected quality of the produced pseudo-random stream?
    
    See attached.
    
    >>> Should we perhaps also add a warning that the same seed is not 
    >>> guaranteed to produce the same sequence across different (major?) 
    >>> versions?
    >>
    >> I wouldn't bother, on the grounds that then we'd need such disclaimers
    >> in a whole lot of places.  Others might see it differently though.
    >
    > Agreed,
    
    Agreed.
    
    > though I think when the release notes are written, they ought
    > to warn that the sequence will change with this release.
    
    Yes.
    
    -- 
    Fabien.
  7. Re: random() function documentation

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-04-12T15:03:41Z

    Fabien COELHO <coelho@cri.ensmp.fr> writes:
    >>> How about we just say "uses a linear-feedback shift register algorithm"?
    
    >> I think it'd be sufficient to just say that it's a deterministic
    >> pseudorandom number generator. I don't see much value in documenting
    >> the internal algorithm used.
    
    > Hmmm… I'm not so sure. ISTM that people interested in using the random 
    > user-facing variants (only random?) could like a pointer on the algorithm 
    > to check for the expected quality of the produced pseudo-random stream?
    
    > See attached.
    
    I don't want to get that specific.  We were not specific before and
    there has been no call for such detail in the docs.  (Unlike
    closed-source software, anybody who really wants algorithmic details
    can find all they want to know in the source code.)  It would just
    amount to another thing to forget to update next time someone changes
    the algorithm ... which is a consideration that leads me to favor
    Dean's phrasing.
    
    			regards, tom lane
    
    
    
    
  8. Re: random() function documentation

    Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> — 2022-04-12T15:12:06Z

    Dean Rasheed <dean.a.rasheed@gmail.com> writes:
    
    > On Mon, 11 Apr 2022 at 20:20, Tom Lane <tgl@sss.pgh.pa.us> wrote:
    >>
    >> >> How about we just say "uses a linear-feedback shift register algorithm"?
    >
    > I think it'd be sufficient to just say that it's a deterministic
    > pseudorandom number generator. I don't see much value in documenting
    > the internal algorithm used.
    >
    >> > Should we
    >> > perhaps also add a warning that the same seed is not guaranteed to
    >> > produce the same sequence across different (major?) versions?
    >>
    >> I wouldn't bother, on the grounds that then we'd need such disclaimers
    >> in a whole lot of places.  Others might see it differently though.
    >
    > Agreed, though I think when the release notes are written, they ought
    > to warn that the sequence will change with this release.
    
    WFM on both points.
    
    > Regards,
    > Dean
    
    - ilmari
    
    
    
    
  9. Re: random() function documentation

    Tom Lane <tgl@sss.pgh.pa.us> — 2022-04-12T15:22:31Z

    =?utf-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= <ilmari@ilmari.org> writes:
    > Dean Rasheed <dean.a.rasheed@gmail.com> writes:
    >> I think it'd be sufficient to just say that it's a deterministic
    >> pseudorandom number generator. I don't see much value in documenting
    >> the internal algorithm used.
    
    > WFM on both points.
    
    Sold then, I'll make it so.
    
    			regards, tom lane