問題描述
我想創建一個接受雙均值
、雙偏差
并返回一個正態分布的隨機數的函數.
I would like to create a function that accepts Double mean
, Double deviation
and returns a random number with a normal distribution.
例如:如果我傳入 5.00 作為平均值和 2.00 作為偏差,68% 的時間我會得到一個介于 3.00 和 7.00 之間的數字
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
我的統計數據有點弱......任何人都知道我應該如何處理這個問題?我的實現將是 C# 2.0,但只要數學函數是標準的,就可以用您選擇的語言回答.
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?
預先感謝您的幫助.
推薦答案
參見這篇 CodeProject 文章:簡單的隨機數生成.代碼很短,可以從均勻分布、正態分布和指數分布中生成樣本.
See this CodeProject article: Simple Random Number Generation. The code is very short, and it generates samples from uniform, normal, and exponential distributions.
這篇關于C# 普通隨機數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!