首页 > 其他分享 >c随机数函数

c随机数函数

时间:2023-01-10 08:36:06浏览次数:33  
标签:rand 函数 int num 随机数 100 include

生成一个随机数

1.添加一个随机数种子srand(time(NULL))

2.添加头文件

  <stdlib.h>

  <time.h>

3.生成随机数 int n=rand() %100(对100取余,生成随机数的范围0-99)

 

#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include <unistd.h>
int main(){

srand(time(NULL));
int num;
for(;;){num=rand()%100;
    printf("%d\n",num);
    sleep(2);
}
system("pause");
return 0;

}

 

标签:rand,函数,int,num,随机数,100,include
From: https://www.cnblogs.com/miwaiwai/p/17039047.html

相关文章