zoukankan      html  css  js  c++  java
  • PHP固定长度字符串

    /**
     * 获取固定长度随机字符串
     * @param $n
     * @return string
     * @throws Exception
     */
    function gf_rand_str($n) {
        if (!is_int($n)) {
            throw new Exception('argument must be int');
        }
        $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $str = '';
        for ($i=0; $i<$n; $i++) {
            $str .= $alpha[rand(0, 35)];
        }
        return $str;
    }

    前三位字母后三位数字:

    function invite_num($len = 6)
    {
        $en_chars = [
            "A", "B", "C", "D", "E", "F", "G",
            "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
            "S", "T", "U", "V", "W", "X", "Y", "Z"
        ];
        $num_chars = [
            "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
        ];
        $en_shuf = shuffle($en_chars);    // 将数组打乱
        $num_shuf = shuffle($num_chars);
        $output = "";
        for ($i = 0; $i < 3; $i++) {
            $output .= $en_chars[mt_rand(0, $len)];
        }
        $output .= substr(getMicroSecondsTimestamp(), 11, 1);
        $output .= rand(10, 99);
        return $output;
    }
    function getMicroSecondsTimestamp()
    {
        $time = microtime();
        return substr($time, 11, 10) . str_pad(substr($time, 0, 8) * 1000000,
                6, "0", STR_PAD_LEFT);
    }
  • 相关阅读:
    LCA——最近公共祖先
    P1576 最小花费
    CollaQ复现
    人体姿态估计Alphapose安装
    mingw安装
    MADDPG实现
    MFMARL(Mean Field Multi-Agent Reinforcement Learning)实现
    MASK_RCNN实现
    Insightface实现
    .tar.002文件怎么解压
  • 原文地址:https://www.cnblogs.com/sgm4231/p/12073121.html
Copyright © 2011-2022 走看看