逍遥派七宝指环:C语言中的随机函数问题

来源:百度文库 编辑:高校问答 时间:2024/05/04 16:53:43
请问:C语言中的随机函数rand()怎么用,我不会了。

函数名: random
功 能: 随机数发生器
用 法: int random(int num);
程序例:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>/* prints a random number in the range 0 to 99 */
int main(void)
{
randomize(); printf("Random number in the 0-99 range: %d\n",
random (100));
return 0;
}

#include <stdlib.h>
#include <stdio.h>
#include <time.h>/* prints a random number in the range 0 to 99 */
void main(void)
{
srand( (unsigned)time( NULL ) );
printf("Random number in the 0-99 range: %d\n", rand()%100);
}