<?php

namespace SRVX\Utils;
class Rand
{
    public static function randString(int $len = 16, string $char = '')
    {
        $c       = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-={}[]:";\'<>?,./~`';
        $char    = $char == '' ? $c : $char;
        $charLen = strlen($char);
        $str     = '';
        for ($i = 0; $i < $len; $i++) {
            $str .= $char[rand(0, $charLen - 1)];
        }
        return $str;
    }

    /**
     * 生成指定位数随机数
     * @param $length
     * @return int
     */
    public static function randomNumByLength($length)
    {
        $min = pow(10, $length - 1) ;
        $max = pow(10, $length) - 1;
        return mt_rand($min, $max);
    }
}