数字信号产生之拉普拉斯分布的随机数

发布时间:2016-12-10 18:54:32 编辑: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); }     laplace.h   #pragma once #include "uniform.h" #include <math.h> class laplace { private:  double beta, u1, u2, x, generate_num;  int s, i, j;  int * seed; public:  laplace() {}  void generate();  double random_number(double, int *); }; double laplace::random_number(double beta, int * seed) {  uniform unif_num;  u1 = unif_num.random_number(0.0, 1.0, seed);  u2 = unif_num.random_number(0.0, 1.0, seed);  if (u1 <= 0.5)   x = -beta * log(1 - u2);  else   x = beta * log(u2);  return (x); }     laplace.cpp   //产生50个参数beta为1.5的拉普拉斯分布的随机数 #include <iostream> #include <iomanip> #include "laplace.h" using namespace std; void main() {  laplace solution;  solution.generate(); } void laplace::generate() {  cout << "输入拉普拉斯分布的参数:";  cin >> beta;  cout << "输入随机数的种子:";  cin >> s;  cout << "生成的随机数结果为:" << endl;  for (i = 0; i < 10; i++)  {   for (j = 0; j < 5; j++)   {    generate_num = random_number(beta, &s);    cout << setw(10) << generate_num;   }   cout << endl;  } }  

上一篇:scull源码分析
下一篇:Eclipse常用命令

相关文章

相关评论