Re: [PATCH] random_normal function

From: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>
To: Paul Ramsey <pramsey(at)cleverelephant(dot)ca>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] random_normal function
Date: 2022-12-09 18:39:22
Message-ID: F08A1B23-56E8-49E8-9D0D-4E7CDFBCA702@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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?

+-- The semantics of a negative stddev are not well defined
+SELECT random_normal(mean := 0, stddev := -1);
+ random_normal
+---------------------
+ -1.0285744583010896
+(1 row)
+
+SELECT random_normal(mean := 0, stddev := '-Inf');
+ random_normal
+---------------
+ Infinity
+(1 row)
+
+-- This result may be defensible...
+SELECT random_normal(mean := '-Inf', stddev := 'Inf');
+ random_normal
+---------------
+ -Infinity
+(1 row)
+
+-- but if so, why is this NaN?
+SELECT random_normal(mean := 'Inf', stddev := 'Inf');
+ random_normal
+---------------
+ NaN
+(1 row)
+


Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2022-12-09 18:40:55 Re: add \dpS to psql
Previous Message Jacob Champion 2022-12-09 18:21:21 RFC: logical publication via inheritance root?