package com.ruoyi.common.utils;

import cn.hutool.core.util.RandomUtil;

import java.util.Random;

public class NumberUtils {


    /**
     * 生成首页不是0的随机数
     * @param len
     * @return
     */
    public static String generatePwd(int len) {
        String pass = RandomUtil.randomNumbers(6);
        if (pass.charAt(0) == '0') {
            pass = RandomUtil.randomString("123456789", 1) + pass.substring(1);
        }
        return pass;
    }

    public static String getRandom(int len) {
        int rs = (int) ((Math.random() * 9 + 1) * Math.pow(10, len - 1));
        return String.valueOf(rs);
    }

    public static String getRandom1(int len) {
        Random r = new Random();
        StringBuilder rs = new StringBuilder();
        for (int i = 0; i < len; i++) {
            rs.append(r.nextInt(10));
        }
        return rs.toString();
    }

    public static boolean isNumeric(String str){
        if(StringUtils.isNotEmpty(str)){
            str = str.trim();
        }
        for(int i=str.length();--i>=0;){
            int chr=str.charAt(i);
            if(chr<48 || chr>57){
                return false;
            }
        }
        return true;
    }

    public static boolean isPositive(Long v) {
        return null != v && v > 0L;
    }

    public static void main(String[] args) {
        System.out.println(getRandom1(8));
        System.out.println(getRandom(8));
    }

}
