java生成随机字符串

    private static int getRandom(int count) {
          return (int) Math.round(Math.random() * (count));
      }
	
	private static String string = "abcdefghijklmnopqrstuvwxyz";	
	
	private static String getRandomString(int length){
		StringBuffer sb = new StringBuffer();
		int len = string.length();
		for (int i = 0; i < length; i++) {
			sb.append(string.charAt(getRandom(len-1)));
		}
		return sb.toString();
	}

 

posted on 2015-01-21 17:56  张飞_  阅读(22966)  评论(2编辑  收藏  举报

导航