c语言rand,srand用法

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
using namespace std;
int main() {//rand, time随机函数的用法 

  while (1) {
    Sleep(1000);
    srand(time(0));//随机种子 time(0)返回时间值 
    int r = rand() % 100 + 1;//随机输出一个0到100内得数
    printf("%d\n", r);
  } 
  return 0;
}

猜你喜欢

转载自blog.csdn.net/zwhsoul/article/details/80146566
今日推荐