Re: [PATCH] random_normal function

From: Paul Ramsey <pramsey(at)cleverelephant(dot)ca>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] random_normal function
Date: 2022-12-08 22:57:34
Message-ID: 974508BA-D770-400B-8766-EC3220F37C42@cleverelephant.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Dec 8, 2022, at 2:40 PM, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> wrote:
>
> On Thu, Dec 8, 2022 at 2:53 PM Paul Ramsey <pramsey(at)cleverelephant(dot)ca> wrote:
>
> random_normal(stddev float8 DEFAULT 1.0, mean float8 DEFAULT 0.0)
>
> Any particular justification for placing stddev before mean? A brief survey seems to indicate other libraries, as well as (at least for me) learned convention, has the mean be supplied first, then the standard deviation. The implementation/commentary seems to use that convention as well.

No, I'm not sure what was going through my head, but I'm sure it made sense at the time (maybe something like "people will tend to jimmy with the stddev more frequently than the mean"). I've reversed the order

> Some suggestions:

Thanks! Taken :)

> And a possible micro-optimization...
>
> + bool rescale = true
> + if (PG_NARGS() = 0)
> + rescale = false
> ...
> + if (rescale)
> ... result = (stddev * z) + mean
> + else
> + result = z

Feels a little too micro to me (relative to the overall cost of the transform from uniform to normal distribution). I'm going to leave it out unless you violently want it.

Revised patch attached.

Thanks!

P

Attachment Content-Type Size
random_normal_02.patch application/octet-stream 6.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul Ramsey 2022-12-08 22:58:02 Re: [PATCH] random_normal function
Previous Message Tom Lane 2022-12-08 22:57:09 Re: Error-safe user functions