JAVA 生存 随即6 位 字母+数字

Java代码   收藏代码
  1. /** 
  2.  * 0-9 ASC 48-57 
  3.  * A-Z ASC 65-90 
  4.  * a-z ASC 97-122 
  5.  */  
  6. package com.nutsbling.rand;  
  7.   
  8. import java.util.Random;  
  9.   
  10. public class RandNumCharacter {  
  11.       
  12.     /** 
  13.      *  
  14.      * @param begin 区间段的最小集合 
  15.      * @param end 区间段的最大集合 
  16.      * @return 
  17.      */  
  18.     public static int iRandom(int []begin, int []end){  
  19.         Random r =new Random();  
  20.         int index = r.nextInt(begin.length);   
  21.         int size = end[index]-begin[index];  
  22.         return r.nextInt(size)+begin[index]; //产生随机数后的ASC  
  23.           
  24.     }  
  25.   
  26.     /** 
  27.      * @param args 
  28.      */  
  29.     public static void main(String[] args) {  
  30.         // TODO Auto-generated method stub  
  31.         int []begin={48,65,97};  
  32.         int []end={57,90,122};  
  33.         char []c = new char[6];  
  34.         for(int i=0;i<6;i++){  
  35.             c[i]=(char) iRandom(begin, end);  
  36.           
  37.         }  
  38.         System.out.println(new String(c));  
  39.     }  
  40.   
  41. }  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值