概述
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);
}
cauthy.h
#pragma once
#include <math.h>
#include "uniform.h"
#define PI 3.1415926
class cauthy
{
private:
double a, b, u, x, generate_num;
int * seed;
int s, i, j;
public:
cauthy() {}
void generate();
double random_number(double, double, int *);
};
double cauthy::random_number(double a, double b, int * seed)
{
uniform unif_num;
u = unif_num.random_number(0.0, 1.0, seed);
x = a - b / tan(PI * u);
return (x);
}
cauthy.cpp
//产生50个参数alpha = 1、beta = 1的柯西分布的随机数
#include <iostream>
#include <iomanip>
#include "cauchy.h"
using namespace std;
void main()
{
cauthy solution;
solution.generate();
}
void cauthy::generate()
{
cout << "输入柯西分布的参数alpha:";
cin >> a;
cout << "输入柯西分布的参数beta:";
cin >> b;
cout << "输入随机数的种子:";
cin >> s;
cout << "生成随机数的结果为:" << endl;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 5; j++)
{
generate_num = random_number(a, b, &s);
cout << setw(10) << generate_num;
}
cout << endl;
}
}
最后
以上就是端庄导师为你收集整理的数字信号产生之柯西分布的随机数的全部内容,希望文章能够帮你解决数字信号产生之柯西分布的随机数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复