/**
     * 返回长度为【strLength】的随机数,在前面补0
     * @param strLength 长度
     * @return 随机数
     */
    public static String getFixLengthString(int strLength) {

        Random rm = new Random();

        // 获得随机数
        double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);

        // 将获得的获得随机数转化为字符串
        String fixLengthString = String.valueOf(pross);

        // 返回固定的长度的随机数
        return fixLengthString.substring(1, strLength + 1);
    }

转自 https://www.jianshu.com/p/a272f3da6559

相关文章:

  • 2021-11-27
  • 2021-06-23
  • 2021-11-24
猜你喜欢
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
相关资源
相似解决方案