Java 如何生成一个 8 位的字母和数字组合随机字符串

使用下面的方法:

RandomStringUtils.randomAlphanumeric(10)

使用的类是:

org.apache.commons.lang.RandomStringUtils

Operations for random Strings.

Currently private high surrogate characters are ignored. These are unicode characters that fall between the values 56192 (db80) and 56319 (dbff) as we don’t know how to handle them. High and low surrogates are correctly dealt with – that is if a high surrogate is randomly chosen, 55296 (d800) to 56191 (db7f) then it is followed by a low surrogate. If a low surrogate is chosen, 56320 (dc00) to 57343 (dfff) then it is placed after a randomly chosen high surrogate.

你可以使用下面的方法:

logger.debug("RandomStringUtils - [{}]", RandomStringUtils.randomAlphanumeric(10));

 

程序输出为:

2018/12/30 17:01:57 DEBUG [com.ossez.codebank.lang.tests.NumberTest] - 9ZhT1dDl49

 

您可以在保留原文链接的情况下转载:HoneyMoose » Java 如何生成一个 8 位的字母和数字组合随机字符串

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏