# The Box-Muller method create or replace function rnv(mean, sd, u, v) as (select ( sqrt(-2 * ln(u)) * cos(2 * pi() * v) * sd) + mean); create or replace table t as (with rows as (select random() as u, random() as v from unnest(range(0,1000))) select rnv(0, 0.5, u, v) as rnv from rows); from t limit 5; select avg(rnv) as average, stddev_samp(rnv) as 'sample stddev', stddev_pop(rnv) as 'population stddev' from t;