RandomUtil.java 1015 B

123456789101112131415161718192021222324252627282930
  1. package com.example.xiaoshiweixinback.business.utils;
  2. import java.util.Random;
  3. public class RandomUtil {
  4. /**
  5. * 随机验证码
  6. * @return
  7. */
  8. public static String getSixRandom(){
  9. return String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, 5)));
  10. }
  11. private static String[] STR_ARR = new String[] { "a", "b", "c", "d", "e",
  12. "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
  13. "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E",
  14. "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  15. "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5",
  16. "6", "7", "8", "9", "0" };
  17. public static String generateRandomString(int length) {
  18. StringBuilder sb = new StringBuilder();
  19. Random rand = new Random();
  20. for (int i = 0; i < length; i++) {
  21. sb.append(STR_ARR[rand.nextInt(STR_ARR.length)]);
  22. }
  23. return sb.toString();
  24. }
  25. }