Skip to content

Instantly share code, notes, and snippets.

@xtender
Created July 23, 2020 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtender/e65fd2cb0e82ce071150ecd517e0834a to your computer and use it in GitHub Desktop.
Save xtender/e65fd2cb0e82ce071150ecd517e0834a to your computer and use it in GitHub Desktop.
dbms_random gaussian
SQL> select random_gauss(3,4,1,5) g from dual connect by level<=10;
G
----------
4.86149705
3.62906844
2.55838621
1.38483471
2.02562505
2.70431185
1.56148613
1.46706992
3.69866968
1.30428931
10 rows selected.
create or replace function random_gauss(p_mean number:=0, p_dev number:=1, p_min number:=null, p_max number:=null)
return number
as
res number;
function gauss return number as
begin
return dbms_random.normal()*p_dev + p_mean;
end;
begin
res:=gauss();
while not res between p_min and p_max loop
res:=gauss();
end loop;
return res;
end;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment