SaltUtil.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cn.com.lzt.tools;
  2. import java.util.Random;
  3. /**
  4. *
  5. * ClassName: SaltUtil
  6. *
  7. * @Description: 加盐处理
  8. * @author zhijia.wang
  9. * @date 2017-6-9下午2:20:36
  10. */
  11. public class SaltUtil {
  12. private static String[] WORDS = new String[] { "a", "b", "c", "d", "e",
  13. "f", "g", "h", "i", "j", "k", "m", "n", "p", "q", "r", "s", "t",
  14. "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
  15. "H", "I", "J", "K", "M", "N", "P", "Q", "R", "S", "T", "U", "V",
  16. "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8",
  17. "9" };
  18. public static String randomSalt(int size) {
  19. StringBuffer sb = new StringBuffer();
  20. Random random = new Random();
  21. for (int i = 0; i < size; i++) {
  22. sb.append(WORDS[random.nextInt(WORDS.length)]);
  23. }
  24. return sb.toString();
  25. }
  26. public static int randon6Num() {
  27. return new Random().nextInt(899999) + 100000;
  28. }
  29. public static int randon5Num() {
  30. return new Random().nextInt(89999) + 10000;
  31. }
  32. public static int randon4Num() {
  33. return new Random().nextInt(8999) + 1000;
  34. }
  35. public static int randon3Num() {
  36. return new Random().nextInt(899) + 100;
  37. }
  38. }