参考原文:http://zhidao.baidu.com/link?url=nB3BT69wmUAiSPfKGgK5Q7HOFFP9AIE04AthreRd9yYcwKhUQsQRWlMdMhW1Qm4P7VqyHREaRqeL_6v6q8B2K_

1.使用org.apache.commons.lang.RandomStringUtils.randomAlphanumeric(10)取数字字母随机10位;
//取得一个3位随机数字字符串 
String num = RandomStringUtils.random(3, false, true); 
//取得一个3位的随机字母,并将字母转化为大写字母
String str = RandomStringUtils.random(3, true, false);
//生成长度为count的随机ASCII字串
RandomStringUtils.randomAscii(int count) 
//生成长度为count的随机字母字串
RandomStringUtils.randomAlphabetic(int count)
2.使用Random rad = new Random();
int radnum = rad.nextInt(10);//取小于10的正整数
3.取范围内的随机数:
Math.round(Math.random() * (255 - 1) + 1)最大255,最小1

相关文章:

  • 2022-01-09
  • 2022-02-02
  • 2022-01-22
  • 2022-12-23
  • 2021-06-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2021-05-22
  • 2021-05-07
  • 2021-11-18
  • 2021-05-13
  • 2022-12-23
相关资源
相似解决方案