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

获取时间

#include 
#include 
int main() {
    printf("%ld\n", time(NULL));
    return 0;
}

 

对应python中

import time
print(time.time())

 

生成随机骰子数:

#include 
#include 
#include 
int main() {
    srand(time(NULL));
    for (int i = 0; i < 10; ++i) {
        printf("%d\n", rand() % 6 + 1);
    }
}

 

你可能感兴趣的:(time.h中time(NULL),stdlib.h中srand(), rand())