c语言生成随机数

记录示例,留作自用

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    //设置当前时间戳作为rand的种子
    srand((unsigned int)time(NULL));
    //生成随机数
    int rnd = rand();
    printf("生成了随机数: %d\n", rnd);
    return 0;
}

参考1: Linux C语言生成随机数
参考2:c语言产生随机数的方法

posted @ 2021-11-08 14:45  BrianSun  阅读(503)  评论(0)    收藏  举报