Re: Functions to return random numbers in a given range - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: Functions to return random numbers in a given range
Date
Msg-id CAEZATCX=EVZJdqGTgB-4W4Fw4Un8bdnMng1+v4ioFxfTWe4nRQ@mail.gmail.com
Whole thread Raw
In response to Re: Functions to return random numbers in a given range  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: Functions to return random numbers in a given range
List pgsql-hackers
On Tue, 27 Feb 2024 at 17:33, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
>
> On Sat, 24 Feb 2024 at 17:10, Tomas Vondra
> >
> > I did a quick review and a little bit of testing on the patch today. I
> > think it's a good/useful idea, and I think the code is ready to go (the
> > code is certainly much cleaner than anything I'd written ...).
>

Based on the reviews so far, I think this is ready for commit, so
unless anyone objects, I will do so in a day or so.

As a quick summary, this adds a new file:

src/backend/utils/adt/pseudorandomfuncs.c

which contains SQL-callable functions that access a single shared
pseudorandom number generator, whose state is private to that file.
Currently the functions are:

  random() returns double precision                 [moved from float.c]
  random(min integer, max integer) returns integer  [new]
  random(min bigint, max bigint) returns bigint     [new]
  random(min numeric, max numeric) returns numeric  [new]
  random_normal() returns double precision          [moved from float.c]
  setseed(seed double precision) returns void       [moved from float.c]

It's possible that functions to return other random distributions or
other datatypes might get added in the future, but I have no plans to
do so at the moment.

Regards,
Dean



pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation
Next
From: Peter Eisentraut
Date:
Subject: Re: Built-in CTYPE provider