非常奇怪啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这是一个随机数产生器:
#include "sys\timeb.h"
#include "sys\types.h"
#include "time.h"
#include "iostream.h"
#include "conio.h"
#define alpha 3.95
double init(void);
int random(int x)
{
int ran=0;
static double f=-1.0;
if(f==-1.0)f=init();
else
f=alpha*f*(1.0-f);
return x*f;}
double init(void)
{
double f0;
struct timeb *pr;
for(;;)
{
ftime(pr);
f0=pr->millitm*0.9876543*0.001;
if(f0<0.001)continue;
break;
}
return f0;
}
void main(void)
{
clrscr();
int s=8;
while(s>=0)
{
cout<<random(8)<<endl;//????????奇怪的现象出现了,当把random函数放到循环体内是,运行的结果会出现NULL POINTER ..的错误提示.
s--;}
/*cout<<random(8)<<endl;//???????去掉循环,连续写几个RANDOM却运行良好,没有错误提示
cout<<random(8)<<endl;
cout<<random(8)<<endl;
cout<<random(8)<<endl;
cout<<random(8)<<endl;
cout<<random(8)<<endl;*/
}
//这是什么原因???????????????????????????????????????????????????????????????????