<?php
/**
 * Created by PhpStorm
 * User:林志杰
 * Email:598287049@qq.com
 * Motto:纵有疾风起,人生不言弃!
 * Time:2020/1/14 0:08
 */

declare(strict_types=1);

namespace app\common\lib;

/**
 * 记录和数字相关的类库中的方法
 * Class Num
 * @package app\common\lib
 */
class Num
{
    /**
     * 生成随机验证码
     * @param int $len 4位或者6位
     * @return int
     * @throws \Exception
     */
    public static function getCode(int $len = 4): int
    {
        $code = random_int(1000, 9999);
        if ($len === 6) {
            $code = random_int(100000, 999999);
        }

        return $code;
    }
}