C++高斯分布/正态分布源代码

C++高斯分布/正态分布源代码_第1张图片
这里提供了三套完整源代码,直接可以
https://www.bilibili.com/read/cv19731449

源码1

注意:需要确保在 IDE 的编译器中启用了C++11支持。

#include
#include
#include
using namespace std;

int main()
{
	/* Create random engine with the help of seed */
	unsigned seed = chrono::steady_clock::now().time_since_epoch().count();
	default_random_engine e(seed);

	/* declaring normal distribution object 'distN' and initializing its mean and standard deviation fields. */
	/* Mean and standard deviation are distribution parameters of Normal distribution. Here, we have used mean=5, and standard deviation=2. You can take mean and standard deviation as per your choice */
	normal_distribution<double> distN(5, 2);

	int n;
	cout << "\nEnter no. of samples: ";
	cin >> n;
	cout << "\nNormal distribution for " << n << " samples (mean=5, standard deviation=2) =>\n";
	for (int i = 1; i <= n; i++)
	{
		cout << i << ". " << distN(e) << "\n";
		//cout << distN(e) << endl;
	}

	return 0;
} 

作者:测绘途夫 https://www.bilibili.com/read/cv19731449 出处:bilibili
效果:
C++高斯分布/正态分布源代码_第2张图片

你可能感兴趣的:(C/C++,c++,高斯分布,正态分布)