📄 sourcegenclass.cpp
字号:
// SourceGenClass.cpp: implementation of the SourceGenClass class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mod_demod.h"
#include "SourceGenClass.h"
#include "head.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
SourceGenClass::SourceGenClass(long points,CString filename)
{
num_of_points=points;
out_put_filename=filename;
}
SourceGenClass::~SourceGenClass()
{
}
////////////////////////////////
double SourceGenClass::uniform(double a,double b,long *seed)
{
double t;
*seed=2045*(*seed)+1;
*seed=*seed-(*seed/1048576)*1048576;
t=(*seed)/1048576.0;
t=a+(b-a)*t;
return t;
}
//////////////////////////////
void SourceGenClass::run()
{
CFile outf(out_put_filename,CFile::modeCreate|CFile::modeWrite);
if(!outf)
{
cout<<"Error occured when create file"<<out_put_filename<<endl;
getch();
exit(1);
}
unsigned rand_max;
long i;
float *x;
long seed;
x=(float *)malloc(num_of_points*sizeof(float));
if(!x) exit(1);
rand_max=32760;
srand(rand_max);
seed=rand();
for(i=0;i<num_of_points;i++)
x[i]=uniform(-1.0,1.0,&seed);
outf.WriteHuge(x,num_of_points*sizeof(float));
outf.Close();
free(x);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -