C语言随机函数
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand((unsigned)time(0)); //time函数time.h库
printf("%c\n",rand()%26+'A');//printf函数 stdio.h库
srand((unsigned)time(0)*(rand()%100));//srand函数和rand函数 stdlib.h库
printf("%c\n",rand()%26+'A');
return 0;
}
srand(unsigned int)函数必须带形参,形参类型为unsigned类型
time()函数获取当前时间
rand()函数产生0~RAND_MAX间的随机数,若未调用srand()函数设置随机数种子,则随机数种子默认为1