Created
July 23, 2020 00:05
-
-
Save xtender/e65fd2cb0e82ce071150ecd517e0834a to your computer and use it in GitHub Desktop.
dbms_random gaussian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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