math
来源:互联网 发布:余文乐潮牌cmss淘宝店 编辑:程序博客网 时间:2024/05/16 19:04
Math.random():产生一个[0,1)之间的随机数。
返回指定范围的随机数(m-n之间)的公式[1]:Math.random()*(n-m)+m;
例:
生成一个6位的随机字符串:
public static void main(String[] args){
String result="";
for(int i=0;i<6;i++){
//生成97-122的int型的整型
int intValue=(int)(Math.random()*26+97);
//将intValue强制转化成char类型后接到resul后面
result=result+(char)intValue;
}
//输出字符串
System.out.println(result);
}
0 0
- Math
- math
- Math
- Math
- Math
- Math
- math
- Math
- math
- Math
- Math
- Math
- Math
- Math
- Math
- Math
- Math
- Math
- C可变参数函数 实现
- 关于Fragment的杂谈
- linux编程-进程简介
- 取bundle 图片
- SVN强制在提交时要求添加注释说明(windows平台)
- math
- UrlRewriteFilter 学习笔记
- Leetcode 贪心 Best Time to Buy and Sell StockII
- js中两个等于号和三个等于号的区别
- vc操作注册表
- “command line option syntax error,Type command/?for help
- C++ 详细解说 STL 排序(Sort)
- android代码优化
- 事件模块(二)ngx_epoll_module详解