rand()函数用来产生随机数

srand()函数用来设计随机数种子


1.rand()函数:

头文件:<stdlib.h>

函数原型:int rand(void)


2.srand()函数

头文件:<stdlib.h>

函数原型:void srand(unsigned int seed)

其中,参数seed是整数,通常可以利用time(NULL)__当前的时间戳 或者geypid(NULL)__当前系统进程id 此类返回值作为参数seed


例:

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

srand((unsigned int)time(NULL));
int random = rand();