`
uule
  • 浏览: 6358032 次
  • 性别: Icon_minigender_1
  • 来自: 一片神奇的土地
社区版块
存档分类
最新评论

BossUtil - 生成随机字符串

 
阅读更多
public class BossUtil {
	private static Logger logger=Logger.getLogger(BossUtil.class);
	public static final int nPageSize = 10;
	
	public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    public static final String letterChar = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
    public static final String numberChar = "023456789";

    /*
     * 获取随机字符串
     */
    public static String generateString(int length){  //参数为返回随机数的长度
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			sb.append(allChar.charAt(random.nextInt(allChar.length())));
		}
		return sb.toString();
    }
    
    public static String generateNumber(int length){  //参数为返回随机数的长度
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			sb.append(numberChar.charAt(random.nextInt(numberChar.length())));
		}
		return sb.toString();
    }
    
    
	public static void main(String[] args)
	{
		System.out.print(generateNumber(6));

	}

 。。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics