c#使用普通dstr的随机数生成
问题说明
我是 c# 新手,我正在尝试从 c# 中的正态分布生成数字.我搜索了网络,我只找到了一些代码.我想使用现成的内置函数而不是代码!!有什么建议吗?
i am new to c# and i am trying to generate numbers ifrom normal distribution in c#. I serched the web and i found only some code. I would like to use a ready built in function and not a code!! any suggestions?
正确答案
你仍然需要做一点编码:
You will still need to do a little coding too:
- 定义正态分布.
- 从中取样.
注意,您需要定义一次,然后采样,而不是重新定义.
N.B You need to define it once and then sample as opposed to re-define.
也许这个小类可以提供帮助,那么您可以在代码中需要的地方使用它...
Maybe this little class can help, then you can just use it in your code where you need...
public class BoxMullerNormal
{
private MathNet.Numerics.Distributions.Normal normal;
public BoxMullerNormal(double mean = 0,double std = .01)
{
normal = new MathNet.Numerics.Distributions.Normal(mean,std);
}
public override dynamic getRandom()
{
// Implementation Uses C#MathNet.Numerics Normal Distribution Sampling
return normal.Sample();
}
}
在您的应用程序开始时初始化类以定义法线,然后每次只需调用 getRandom()
即可从中采样.您还可以将该类添加到现有的接口中.
Initialize the class at the start of your app to define the normal, then just call getRandom()
every time to sample from it. You can also add the class to once of your existing Interfaces.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcajkag
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
复制文件夹/文件而不修改属性?
it1352 07-15 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
在不打开短信界面的情况下从 iPhone 应用发送短信?
it1352 07-25