生成十位数的字符串

	@Test
	public void test1() {
		System.out.println(getRandomString(10));
	}

	public static String getRandomString(int length) {
		String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(62);
			sb.append(str.charAt(number));
		}
		return sb.toString();
	}

  

posted @ 2022-11-25 15:54  Sunray0330  阅读(19)  评论(0编辑  收藏  举报