C语言实现随机序列
1、首先打开VC++6.0

2、选择文件,新建

3、选择C++ source file 新建一个空白文档

4、先声明头文件
#include <stdio.h>
#include <timeb.h>

5、写一个函数用于返回随机数序列初值
double Initial()
{
double init;
struct timeb *tmb;
while(1)
{
ftime(tmb);
/*利用DOS系统的时钟产生随机数序列初值*/
init=tmb->millitm*0.9876543*0.001;
if(init>=0.001)
break;
}
return init;
}

6、返回一个(0,1)之间的随机数
double Random(void)
{
static double rndm=-1.0;
if(rndm==-1.0)
rndm=Initial();
else
rndm=3.80*rndm*(1.0-rndm);
return rndm;
}

7、主函数
int main()
{
double randnum;
int i;
puts("*********************************************");
puts("| This program can generate a random number |");
puts("| Press 'q' to quit |");
puts("| Press any other key to generate |");
puts("*********************************************");
while(1)
{
if(getch()=='q')
break;
randnum = Random();
printf ( "\n >> the randnum is:%f\n",randnum );
}
return 0;
}
