time.h中time(NULL),stdlib.h中srand(), rand()

获取时间

#include <stdio.h>
#include <time.h>
int main() {
    printf("%ld
", time(NULL));
    return 0;
}

对应python中

import time
print(time.time())

生成随机骰子数:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main() {
    srand(time(NULL));
    for (int i = 0; i < 10; ++i) {
        printf("%d
", rand() % 6 + 1);
    }
}
原文地址:https://www.cnblogs.com/profesor/p/13196085.html