• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

c#使用普通dstr的随机数生成

用户头像
it1352
帮助1

问题说明

我是 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?

正确答案

#1

你仍然需要做一点编码:

You will still need to do a little coding too:

  1. 定义正态分布.
  2. 从中取样.

注意,您需要定义一次,然后采样,而不是重新定义.

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
系列文章
更多 icon
同类精品
更多 icon
继续加载