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