数字信号处理C语言集(1.1 随机数的产生)

 main.cpp

 

所建工程文件如下图所示

uniform.h

#ifndef _UNIFORM_H_ #define _UNIFORM_H_ double uniform(double a,double b, long int *seed); #endif

 

uniform.cpp
复制代码
#include "uniform.h" #include "stdio.h"
#define Lamda 2045 #define Miu 1 #define M 1048576
double uniform(double a, double b, long int *seed) { double t; *seed = Lamda*(*seed) + Miu; *seed = *seed - (*seed/M)*M; t = (*seed) / (M+0.0); t = a + (b - a)*t; return(t); }
复制代码

uniform_test.h

#ifndef _UNIFORM_TEST_H_
#define _UNIFORM_TEST_H_
void uniform_test(void);
#endif

 uniform_test.cpp

复制代码
#include "uniform_test.h" #include "uniform.h" #include "stdio.h" #include <iostream> #include <iomanip> using namespace std;
void uniform_test(void) { double a =0.0; double b =1.0; double x; long int s=13579; int i,j; printf(" uniform test start! "); for(i=0;i<10;i++) { for(j=0;j<5;j++) { x=uniform(a,b,&s); cout<<setiosflags(ios::fixed)<<setprecision(7); cout << x << ' '; //printf(" %13.7f",x); } cout << ' ' <<endl; //printf(" "); }
}
复制代码
复制代码
//#include "uniform.h"#include  "uniform_test.h" #include<stdio.h>
void main(void) { uniform_test(); getchar(); }
复制代码
原文地址:https://www.cnblogs.com/lueguo/p/3283384.html