java 生成随机字符串

来源:互联网 发布:腾讯公布微信数据 编辑:程序博客网 时间:2024/04/26 15:52
public class SuiJiZiFuChuan {SuiJiZiFuChuan(int x,int y){ for(int j=0;j<y;j++){ for(int i=0;i<x;i++){ int a=(int)(100*Math.random()+100*Math.random()); while(true){ if(a>96&a<123) break; else a=(int)(100*Math.random()+100*Math.random()); } System.out.print((char)a); } System.out.println(); } } }

/**     * 生成指定长度的随机串     */    public static String getRandStr(Integer length){        String str="";        while(str.length()!=length){            str=(Math.random()+"").substring(2,2+length);        }        return str;    }