Skip to content

Instantly share code, notes, and snippets.

@Pet3ris
Forked from 140bytes/LICENSE.txt
Created May 25, 2011 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pet3ris/991724 to your computer and use it in GitHub Desktop.
Save Pet3ris/991724 to your computer and use it in GitHub Desktop.
Generate Normally Distributed Random Variable
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)
}
}
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)}}
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.
{
"name": "normalrandom",
"description": "Generate a normal random variable with given mean, variance.",
"keywords": [
"math",
"random",
"statistics",
"distribution"
]
}
*
*
**
***
*****
*******
***********
***************
*********************
***************************
***********************************
******************************************
**************************************************
********************************************************
*************************************************************
****************************************************************
****************************************************************
*************************************************************
********************************************************
***************************************************
******************************************
***********************************
****************************
********************
**************
***********
*******
*****
***
**
*
@jed
Copy link

jed commented Jul 11, 2011

hey @Pet3ris, could you take the comments out of your package.json?

@Pet3ris
Copy link
Author

Pet3ris commented Jul 11, 2011

@jed, do you mean the description? I cannot find any comments.

@jed
Copy link

jed commented Jul 11, 2011

sorry, i meant the trailing comma in the keywords.

@Pet3ris
Copy link
Author

Pet3ris commented Jul 11, 2011

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