得到指定位数的随机数和随机字母
来源:互联网 发布:软件测试面试题 编辑:程序博客网 时间:2024/05/22 15:38
package com.cr.service;public class Random {/** * 得到指定位数的 随机数整数 * @param length * @return */public static String getIntRandom(int length) { // 纯数字int[] array = new int[length];StringBuilder str = new StringBuilder();for (int i = 0; i < length; i++) {array[i] = (int) (Math.random() * 10);str.append(array[i]);}return str.toString();}/** * 得到指定位数的 随机字母 * @param length * @return */public static String getCharRandom(int length) { // 纯字母int[] array = new int[length];char[] chars = new char[length];StringBuilder str = new StringBuilder();for (int i = 0; i < length; i++) {while (true) {array[i] = (int) (Math.random() * 200);if ((array[i] > 64 && array[i] < 91)|| (array[i] > 96 && array[i] < 123))break;}chars[i] = (char) array[i];str.append(chars[i]);}return str.toString();}/** * 得到指定位数的 随机字母加数字 * @param length * @return */public static String getMixRandom(int length) { // 字母数字混合int[] array = new int[length];char[] chars = new char[length];StringBuffer str = new StringBuffer();int temp = 0;for (int i = 0; i < length; i++) {while (true) {temp = (int) (Math.random() * 1000);if ((temp > 47 && temp < 58) || (temp > 64 && temp < 91)|| (temp > 96 && temp < 123)) {break;}}array[i] = temp;chars[i] = (char) array[i];str.append(chars[i]);}return str.toString();}public static void main(String[] args) {System.out.println(getCharRandom(2));}}
0 0
- 得到指定位数的随机数和随机字母
- java获取指定位数的随机数和字母
- android 随机生成指定位数的字母
- java得到指定位数随机密码(由数字,区分大小写的字母组成)
- 利用随机数随机生成指定位数的字符串
- 使用java Random动态传递位数 生成指定位数的随机字符串-数字字母混合
- web前端js中随机生成指定位数的字母数字、组合字符串可选择字母大小写
- 生成指定位数的随机数
- 生成指定位数的随机数
- 生成指定位数的随机数
- java---大小写字母和数字的随机组合的随机数
- Java产生随机数和随机字母的方法
- 随机产生指定位数的字符,包括数字,大写字母,小写字母
- 得到指定范围的随机数
- Asp得到多少位数的随机函数
- c#生成指定位数的随机数
- 生成正数的指定位数随机数
- 指定位数 产生随机数
- TCP/IP协议 三次握手与四次挥手
- 安卓——ListView的动态添加与删除
- JavaScript应用程序设计:使用Node、HTML5和现代JavaScript类库打造稳健的Web应用——互动出版网
- HDU 5115 Dire Wolf(区间DP)
- 微信跳转appstore的问题
- 得到指定位数的随机数和随机字母
- LeetCode 003 Longest Substring Without Repeating Characters
- 机房收费系统----协作图
- 展示WEB前端开发博文的一个站点
- Maven使用小记
- 正则表达式基本语法
- UNIX系统下,设置ssh登陆不需要密码
- Linux 中如何安装卸载软件
- Node.js实现网络负载均衡器:LoadBalancer.js