int rand(void);

RAND_MAX的值取决于计算机系统。当编写用到随机数字的程序时，您不能主观臆断RAND_MAX的值。可以通过代码查看你的计算机系统中的RAND_MAX的值。
rand函数需要一个初始值，用于启动整个过程的值，被称为随机数字发生器的种子（seed）。Rand函数的实现是这样的，每次运行程序时都把种子设为一个常数值，这就是为什么该函数总是生成序列一样的数值。来看一下下面的代码：

#include<stdlib.h>
#include<stdio.h>

#define NTrials 10

int main()
{
int i;
printf("On this Computer,RAND_MAX is %d.\n",RAND_MAX);
printf("The first %d calls to rand return:\n",NTrials);
for(i=0;i<NTrials;i++)
{
printf("%10d\n",rand());
}
return 0;
}

On this Computer,RAND_MAX is 32767.
The first 10 calls to rand return:
41
18467
6334
26500
19169
15724
11478
29358
26962
24464

srand((int)time(NULL));

int main()
{
int i;
srand((int)time(NULL));  //改变seed的值
printf("The first %d calls to rand return:\n",NTrials);
for(i=0;i<NTrials;i++)
{
printf("%10d\n",rand());
}
return 0;
}

The first 10 calls to rand return:
25865
28610
24648
4690
4180
15648
22709
7359
22068
31563

int main()
{
int i;
srand((int)time(NULL));    //改变seed的值
printf("The Second %d calls to rand return:\n",NTrials);
for(i=0;i<NTrials;i++)
{
printf("%10d\n",rand());
}
return 0;
}

The Second 10 calls to rand return:
26551
24784
7804
11714
7553
21061
20964
15223
16094
18421

看来srand确实有效果哦。

RandomInteger函数的实现如下代码：
int RandomInteger(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<stdlib.h>
#include<stdio.h>
#include<ctime>

#define NTrials 10

int RandomInteger(int low,int high)
{
int k;
double d;
d=(double) rand()/((double) RAND_MAX+1);
k=(int)(d*(high-low+1));
return (low+k);
}

int main()
{
int i;
srand((int)time(NULL));
printf("%d calls to RandomInteger return:\n",NTrials);
for(i=0;i<NTrials;i++)
{
printf("%4d",RandomInteger(0,100));
}
printf("\n");
return 0;
}

10 calls to RandomInteger return:
91    85    98    90     8    37    40    92     8    19

double RandomReal(double low,double high)
{
double d;
d=(double) rand()/ ((double)RAND_MAX+1);
return (low+d*(high-low));
}

#include<stdlib.h>
#include<stdio.h>
#include<ctime>                            //srand所在的头文件

#define NTrials 10

double RandomReal(double low,double high)
{
double d;
d=(double) rand()/ ((double)RAND_MAX+1);
return (low+d*(high-low));
}

int main()
{
int i;
srand((int)time(NULL));
printf("%d calls to RandomReal return:\n",NTrials);
for(i=0;i<NTrials;i++)
{
printf("%6.2f",RandomReal(2.5,12.8));
}
printf("\n");
return 0;
}

10 calls to RandomReal return:
12.68     4.89     9.09     8.53    12.74     5.24    10.30     7.33    12.44     7.93