c#中离散分布随机数的标准函数 [英] standard function for Discretely Distributed Random Numbers in c#

查看:407
本文介绍了c#中离散分布随机数的标准函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有个问题。在c ++ 11中有一个用于离散分布随机数的标准函数discrete_distribution



例如:



Hello all. I have a question. In c++ 11 have a standard function discrete_distribution for Discretely Distributed Random Numbers

Example:

#include <iostream>
#include <random>

int main()
{
  const int nrolls = 10000; // number of experiments
  const int nstars = 100;   // maximum number of stars to distribute

  std::default_random_engine generator;
  std::discrete_distribution<int> distribution {2,2,1,1,2,2,1,1,2,2};

  int p[10]={};

  for (int i=0; i<nrolls; ++i) {
    int number = distribution(generator);
    ++p[number];
  }

  std::cout << "a discrete_distribution:" << std::endl;
  for (int i=0; i<10; ++i)
    std::cout << i << ": " << std::string(p[i]*nstars/nrolls,'*') << std::endl;

  return 0;

}





结果:





Result:

a discrete_distribution:
0: ************
1: *************
2: *****
3: ******
4: ************
5: ************
6: ******
7: ******
8: ************
9: ************









在c#中有标准函数,如c ++中的discrete_distribution ???谢谢大家!





In c# have standard function like discrete_distribution in c++ ??? Thanks all!

推荐答案

.NET Framework中没有这样的类/方法。你必须用C#编写自己的实现。
There is no such class/method in the .NET Framework. You'd have to write your own implementation in C#.


如何写。你有程序吗?请跟我说!
How write. do you have programm? talk me please!


这篇关于c#中离散分布随机数的标准函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆