PHP 生成重复固定随机数邀请码

PHP About 1,177 words

代码

function get_random($len = 3) {
    //range 是将10到99列成一个数组
    $numbers = range(10, 99);
    //shuffle 将数组顺序随即打乱
    shuffle($numbers);
    //取值起始位置随机
    $start = mt_rand(1, 10);
    //取从指定定位置开始的若干数
    $result = array_slice($numbers, $start, $len);
    $random = "";
    for ($i = 0; $i < $len; $i++) {
        $random = $random . $result[$i];
    }
    return $random;
}  

const AAA = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';

function get_random3($len = 3) {
    //range 是将10到99列成一个数组
    $numbers = ['a','b','c','d','e','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8', '9'];
    //shuffle 将数组顺序随即打乱
    shuffle($numbers);
    //取值起始位置随机
    $start = mt_rand(1, 10);
    //取从指定定位置开始的若干数
    $result = array_slice($numbers, $start, $len);
    $random = "";
    for ($i = 0; $i < $len; $i++) {
        $random = $random . $result[$i];
    }
    return $random;
}
//随机数
function get_random2($length = 4) {
    $min = pow(10, ($length - 1));
    $max = pow(10, $length) - 1;
    return mt_rand($min, $max);
}
Views: 3,290 · Posted: 2019-04-08

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh