C++ 简单随机数测试

#include <iostream>
#include <string>
#include <ctime>

int main()
{
    using namespace std;

    // time(0)  都返回自1970年1月1日以来经过的秒数,称为 Unix 时间
    srand(time(0));

    int a;

    for (int i = 0; i < 10; i++) {
        a = rand() % 6 + 1; // 1~6 随机数
        printf("%d\n", a);
    }

    return 0;
}

输出:

3
4
2
6
2
3
6
1
4
6
posted @ 2022-01-13 16:32  double64  阅读(56)  评论(0)    收藏  举报