ios入门之c语言篇——基本函数——1——随机数生成

1、随机数函数

参数返回值解析:

参数:

a:int,数字范围最小值;

b:int,数字范围最大值;

返回值:

1:闰年;

0:非闰年;

备注:

a-b的绝对值不能超过int的最大值(65535);

头文件:

time.h  、stdlib.h;

#include <stdio.h>

#include <time.h>

#include <stdlib.h>

int randomnum(int a,int b)

//返回a-b(包含a和b)之间的整数

srand((unsigned)time(NULL));

//此句仅需主函数出现一次

{

    int cha=b-a+; 

    int temp=rand()%cha;

    return temp+a;

}
上一篇:nginx 反向代理 配置 https 实现http https同时存在


下一篇:Latex 数学符号