-
-
Save Pet3ris/991724 to your computer and use it in GitHub Desktop.
Generate Normally Distributed Random Variable
This file contains hidden or 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
function( | |
// method due to George Marsaglia (http://en.wikipedia.org/wiki/Marsaglia_polar_method) | |
a, // mean (default value 0) | |
b, // variance (default value 1) | |
c, d, e // placeholders | |
){ | |
with (Math){ | |
do d = 2*random() - 1, | |
e = 2*random() - 1, | |
c = d*d + e*e; | |
while (c > 1); | |
return (b||1)*d*sqrt(-2*log(c)/c) + (a||0) | |
} | |
} |
This file contains hidden or 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
function(a,b,c,d,e){with(Math){do d=2*random()-1,e=2*random()-1,c=d*d+e*e;while(c>1);return(b||1)*d*sqrt(-2*log(c)/c)+(a||0)}} |
This file contains hidden or 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Peteris Erins http://peteriserins.com | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or 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
{ | |
"name": "normalrandom", | |
"description": "Generate a normal random variable with given mean, variance.", | |
"keywords": [ | |
"math", | |
"random", | |
"statistics", | |
"distribution" | |
] | |
} |
This file contains hidden or 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
* | |
* | |
** | |
*** | |
***** | |
******* | |
*********** | |
*************** | |
********************* | |
*************************** | |
*********************************** | |
****************************************** | |
************************************************** | |
******************************************************** | |
************************************************************* | |
**************************************************************** | |
**************************************************************** | |
************************************************************* | |
******************************************************** | |
*************************************************** | |
****************************************** | |
*********************************** | |
**************************** | |
******************** | |
************** | |
*********** | |
******* | |
***** | |
*** | |
** | |
* |
sorry, i meant the trailing comma in the keywords.
Oh, indeed, thanks for spotting that. Fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jed, do you mean the description? I cannot find any comments.