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

时间:2020-06-26 19:56:28   收藏:0   阅读:62

获取时间

#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);
    }
}

 

原文:https://www.cnblogs.com/profesor/p/13196085.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!