javaee论坛

普通会员

225648

帖子

335

回复

349

积分

楼主
发表于 2017-09-30 09:57:39 | 查看: 432 | 回复: 0
 1 关于<time.h>的一些函数
 2
 3 1. 使用当前时间作种子,生成随机数
 4
 5 #include <stdio.h>
 6 #include <stdlib.h>
 7 #include <time.h>
 8
 9 int gen_rand_num()
10 {
11     static int first_time = 1;
12
13     if (first_time)
14     {
15         first_time = 0;
16         srand((unsigned int)time(NULL));
17     }
18
19     return rand();
20 }
21
22 2. 打印当前时间
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <time.h>
27
28 int print_time()
29 {
30     time_t now;
31     
32     now = time(NULL);
33     printf("%s", ctime(&now));
34     return 0;
35 }


上一篇:从N 下一篇:压缩编码算法评价 PSNR
您需要登录后才可以回帖 登录 | 立即注册

触屏版| 电脑版

技术支持 历史网 V2.0 © 2016-2017