按书上做的随机数库,编译掷筛子文件时,说找不到randomInt函数,为什么???
各个文件应该放在什么目录下面???
/*
FILE:random.h
*/
#ifndef _random_h
#define _random_h
/*
Function:
*/
int RandomInt(int low,int high);
#endif
实现
/*
FILE:random.c
*/
#include<stdio.h>
#include<stdlib.h>
#include"random.h"
/*
Function:
*/
int RandomInt(int low,int high)
{
int k;
double d;
d=((double)rand() )/ ((double)RAND_MAX+1);
k=(int)(d*(high-low+1));
return (low+k);
}
应用:
#include<stdio.h>
#include"random.h"
int RollDie(void);
int main ()
{
long int count[6]={0};
long int i;
for(i=0;i<100000;i++)
switch(RollDie())
{
case 1:count[0]++;break;
case 2:count[1]++;break;
case 3:count[2]++;break;
case 4:count[3]++;break;
case 5:count[4]++;break;
case 6:count[5]++;break;
}
for ( i=0;i < 6; i++)
printf("%ld\n",count[i]);
system("PAUSE");
return 0;
}
int RollDie(void)
{
return (RandomInt(1,6));
}