C随机范围内的数字
来源:互联网 发布:js 强制刷新 编辑:程序博客网 时间:2024/06/10 11:12
//改编自lua的math.random函数#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h> #define RAND_MAX 2147483647#define lua_Number double int math_random(int down_limit, int up_limit){ lua_Number r = (lua_Number)(rand() % RAND_MAX) / (lua_Number)RAND_MAX; lua_Number l = down_limit; lua_Number u = up_limit; lua_Number ret = floor(r * (u - l + 1 ) + l); return (int)ret;} int main(int argc, char* argv[]){ srand(time(NULL)); printf("RAND_MAX %d\n", RAND_MAX); int i = 0; for (i = 0; i < 100; ++i) { int ret = math_random(-3, 3);printf("%d\n", ret); } return 0;}
1 0
- C随机范围内的数字
- 获取一定范围内的随机数字
- 获取一定范围内的随机数字
- 【Ex.】随机范围内猜数字
- C 语言:打印一定范围内的数字
- 生成一组指定范围内随机数(取50个数字,100到200的随机数字)
- js 返回随机颜色和指定范围内随机数字
- 生成一组指定范围内随机数(取50个数字,100到200的随机数字) LINQ方法
- [Untiy&随机数&C#]怎样加上一个随机的数,并且在一定的范围内
- C语言基础 产生一个0到n-1范围内的随机整数
- 获得指定范围内的随机值
- 生成某个范围内的随机整数公式
- 获得指定范围内的随机值
- java生成某个范围内的随机时间
- Java产生特定范围内的随机整数
- 生成区间范围内的随机日期
- 如何获取一个范围内的随机整数
- 获取一定范围内的随机小数
- Oracle字符替换
- 查看Oracle的redo日志切换频率
- ContentProvider批量导入及事务处理
- HJTextViewPlaceholder
- 202,UIApplication应用程序类
- C随机范围内的数字
- 程序员四门功课
- 算法设计题3.22-栈和队列-第3章-《数据结构习题集》-严蔚敏吴伟民版
- ORACLE-ORA-12154:TNS:could not resolve the connect identifier specified
- unity3d 中IDropHandler 和 IEndDragHandler 优先级别
- mac修改hostname
- java读取文件
- 缩进动画Scaleanimation的一个小示例
- 自定义actionBar --RelativeLayout实现