RandomUtils.java 608 B

12345678910111213141516171819202122232425262728293031
  1. package com.kmall.common.utils;
  2. import java.util.Random;
  3. /**
  4. * /**
  5. * 随机数工具类
  6. *
  7. * @author zhangjun
  8. * @version 1.0.0
  9. * 2018-12-07 16:00
  10. */
  11. public class RandomUtils {
  12. /**
  13. * 获取一个指定位数的随机数
  14. *
  15. * @param bit 指定位数
  16. * @return 随机数
  17. */
  18. public static String getNum(int bit) {
  19. if (bit > 0) {
  20. StringBuffer sb = new StringBuffer();
  21. for (int i = 0; i < bit; i++) {
  22. sb.append(new Random().nextInt(10));
  23. }
  24. return sb.toString();
  25. }
  26. return null;
  27. }
  28. }