Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Normal Random Number [duplicate]

Tags:

I would like to create a function that accepts Double mean, Double deviation and returns a random number with a normal distribution.

Example: if I pass in 5.00 as the mean and 2.00 as the deviation, 68% of the time I will get a number between 3.00 and 7.00

My statistics is a little weak…. Anyone have an idea how I should approach this? My implementation will be C# 2.0 but feel free to answer in your language of choice as long as the math functions are standard.

I think this might actually be what I am looking for. Any help converting this to code?

Thanks in advance for your help.

like image 693
J.Hendrix Avatar asked Oct 26 '09 17:10

J.Hendrix


2 Answers

See this CodeProject article: Simple Random Number Generation. The code is very short, and it generates samples from uniform, normal, and exponential distributions.

like image 142
John D. Cook Avatar answered Oct 27 '22 16:10

John D. Cook


You might be interested in Math.NET, specifically the Numerics package.

Caveat: The numerics package targets .NET 3.5. You may need to use the Iridium package if you are targeting an earlier version...

like image 23
Jason Punyon Avatar answered Oct 27 '22 16:10

Jason Punyon