| From: | Paul Ramsey <pramsey(at)cleverelephant(dot)ca> | 
|---|---|
| To: | Joe Conway <mail(at)joeconway(dot)com> | 
| Cc: | Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: [PATCH] random_normal function | 
| Date: | 2022-12-09 19:11:34 | 
| Message-ID: | EF676327-A7D0-4E68-A27D-33C2DC47D136@cleverelephant.ca | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
> On Dec 9, 2022, at 11:10 AM, Paul Ramsey <pramsey(at)cleverelephant(dot)ca> wrote:
> 
> 
> 
>> On Dec 9, 2022, at 11:01 AM, Joe Conway <mail(at)joeconway(dot)com> wrote:
>> 
>> On 12/9/22 13:51, Paul Ramsey wrote:
>>>> On Dec 9, 2022, at 10:39 AM, Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com> wrote:
>>>>> On Dec 8, 2022, at 1:53 PM, Paul Ramsey <pramsey(at)cleverelephant(dot)ca> wrote:
>>>>> Just a utility function to generate random numbers from a normal
>>>>> distribution. I find myself doing this several times a year, and I am
>>>>> sure I must not be the only one.
>>>> Thanks for the patch.  What do you think about these results?
>>> Angels on pins time! :)
>> 
>> I just noticed this thread -- what is lacking in the normal_rand() function in the tablefunc contrib?
>> 
>> https://www.postgresql.org/docs/current/tablefunc.html#id-1.11.7.52.5
> 
> Simplicity I guess mostly. random_normal() has a direct analogue in random() which is also a core function. I mean it could equally be pointed out that a user can implement their own Box-Muller calculation pretty trivially. Part of this submission is a personal wondering to what extent the community values convenience vs composibility. The set-returning nature of normal_rand() may be a bit of a red herring to people who just want one value (even though normal_rand (1, 0.0, 1.0) does exactly what they want).
No related to the "reason to exist", but normal_rand() has some interesting behaviour under Mark's test cases!
select normal_rand (1, 'Inf', 'Inf'), a from generate_series(1,2) a;
 normal_rand | a 
-------------+---
         NaN | 1
    Infinity | 2
(2 rows)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Corey Huinker | 2022-12-09 22:54:24 | Re: Error-safe user functions | 
| Previous Message | Paul Ramsey | 2022-12-09 19:10:25 | Re: [PATCH] random_normal function |