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

获取时间

#include <stdio.h>
#include <time.h>
int main() {
    printf("%ld\n", 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\n", rand() % 6 + 1);
    }
}

 

posted @ 2020-06-26 19:28  profesor  阅读(188)  评论(0编辑  收藏  举报