random_normal()

A function providing normally-distributed random numbers

random_normal() is a system function  providing normally-distributed random numbers.

random_normal() was added in PostgreSQL 16.

Usage

random_normal ( [ mean double precision [, stddev double precision ]] ) → double precision

random_normal() produces a set of normally distributed random values using Gaussian distribution.

mean speciieds the mean of the normal distribution of values. stddev is the standard deviation of the normal distribution of values.

A function with similar functionality, normal_rand(), is available via the tablefunc contrib module.

Change history

Examples

Basic usage example for random_normal():

postgres=# SELECT random_normal();
   random_normal    
--------------------
 0.7821236960137614
(1 row)

Providing a mean value:

postgres=# SELECT random_normal(5) from generate_series(1,5);
   random_normal   
-------------------
  5.29703419771379
 3.623749811810435
 6.572131718905143
 4.428844367745707
 6.250520372123069
(5 rows)

Categories

System function

See also

random()