zhanggaofeng

C语言 生成随机数

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

void main1(){
    //定义一个时间类型
    time_t ts;//头文件time.h
    //生成随机数种子
    srand((unsigned int)(time(&ts)));
    int num = 0;
    while (1){
        Sleep(1000);
        //rand()随机生成数字
        //如果要限制范围,例如0-5,rand()%6
        printf("%d\n", (int)(rand()%6));
        Sleep(2000);
    }
    system("pause");
}

 

分类:

技术点:

相关文章:

  • 2022-02-06
  • 2022-12-23
  • 2021-10-01
  • 2021-10-01
  • 2021-10-01
  • 2022-01-22
  • 2022-12-23
  • 2021-11-11
猜你喜欢
  • 2021-10-01
  • 2022-02-03
  • 2021-10-01
  • 2021-05-13
  • 2021-12-04
  • 2021-08-02
相关资源
相似解决方案