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+1; 

    int temp=rand()%cha;

    return temp+a;

 

}
View Code

 

posted @ 2015-07-25 16:42  孔凡凯凯  阅读(157)  评论(0编辑  收藏  举报