当前位置 : 主页 > 编程语言 > c语言 >

随机数函数

来源:互联网 收集:自由互联 发布时间:2023-08-28
rand()函数用来产生随机数 srand()函数用来设计随机数种子 1.rand()函数: 头文件:stdlib.h 函数原型:int rand(void) 2.srand()函数 头文件:stdlib.h 函数原型:void srand(unsigned int seed) 其中,参数seed是整数

rand()函数用来产生随机数

srand()函数用来设计随机数种子


1.rand()函数:

头文件:<stdlib.h>

函数原型:int rand(void)


2.srand()函数

头文件:<stdlib.h>

函数原型:void srand(unsigned int seed)

其中,参数seed是整数,通常可以利用time(NULL)__当前的时间戳 或者geypid(NULL)__当前系统进程id 此类返回值作为参数seed


例:

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

srand((unsigned int)time(NULL));
int random = rand();











上一篇:反调试专题丨反调试之NtGlobaFlag
下一篇:没有了
网友评论