好贷网好贷款

数字信号产生之贝努里高斯分布的随机数

发布时间:2016-12-3 2:13:40 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"数字信号产生之贝努里高斯分布的随机数",主要涉及到数字信号产生之贝努里高斯分布的随机数方面的内容,对于数字信号产生之贝努里高斯分布的随机数感兴趣的同学可以参考一下。

uniform.h     #pragma once class uniform { private:  double a, b, generate_num;  int * seed;  int s;  int M, N, i, j; public:  uniform()  {   M = 1048576;   N = 2045;  }  void generate();  double random_number(double, double, int *); }; double uniform::random_number(double a, double b, int * seed) {  (*seed) = N * (*seed) + 1;  (*seed) = (*seed) - ((*seed) / M) * M;  generate_num = static_cast<double>((*seed)) / M;  generate_num = a + (b - a) * generate_num;  return (generate_num); }     gauss.h   #pragma once #include "uniform.h" uniform unif_num; class gauss { private:  double mean, sigma, x, y, generate_num;  int s;  int * seed;  int i, j, m; public:  gauss() {}  void generate();  double random_number(double, double, int *); }; double gauss::random_number(double mean, double sigma, int * seed) {  x = 0;  for (m = 0; m < 12; m++)  {   x += unif_num.random_number(0.0, 1.0, seed);  }  x = x - 6.0;  y = mean + x * sigma;  return (y); }       bernoulli_gauss.h   #pragma once #include "gauss.h" class bernoulli_gauss { private:  double p, mean, sigma, u, x, generate_num;  int * seed;  int s, i, j; public:  bernoulli_gauss() {}  void generate();  double random_number(double, double, double, int *); }; double bernoulli_gauss::random_number(double p, double mean, double sigma, int * seed) {  uniform unif_num;  gauss gau_num;  u = unif_num.random_number(0.0, 1.0, seed);  if (u <= p)   x = gau_num.random_number(mean, sigma, seed);  else   x = 0.0;  return (x); }       bernoulli_gauss.cpp   //产生50个参数p = 0.4、mean = 0、sigma = 1的贝努里_高斯分布的随机数 #include <iostream> #include <iomanip> #include "bernoulli_gauss.h" using namespace std; void main() {  bernoulli_gauss solution;  solution.generate(); } void bernoulli_gauss::generate() {  cout << "输入贝努里_高斯分布的参数p:";  cin >> p;  cout << "输入贝努里_高斯分布的均值:";  cin >> mean;  cout << "输入贝努里_高斯分布的均方差:";  cin >> sigma;  cout << "输入随机数的种子:";  cin >> s;  cout << "生成随机数的结果为:" << endl;  for (i = 0; i < 10; i++)  {   for (j = 0; j < 5; j++)   {    generate_num = random_number(p, mean, sigma, &s);    cout << setw(10) << generate_num;   }   cout << endl;  } }  

上一篇:Tomcat性能调优方案
下一篇:告诉你身体上的秘密,我们需要它?

相关文章

相关评论