Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
用rand创建随机数 - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


需要头

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


例子:

// 创建随机数
int ntime;
srand((unsigned)time(NULL));
ntime = rand()%6;// 创建一个6以内的随机数(0,1,2,3,4,5)


封装了一下:

#define RandNum(min, max)    (rand() % (max - min + 1) + min)


这个语句:

srand((unsigned)time(NULL));

是用来创建随机数种子的。



返回首页


Copyright (C) 2018-2024 huidong