php - 京东上生成100万张优惠券算法问题
阿神
阿神 2017-04-11 10:03:09
0
3
544

京东上生成100万张优惠券,优惠券券号前缀是QA(比如QAK001,QA0U767,QAJUT55,随机的券号),用什么算法能生成100万张不重复的优惠券?这100万张优惠券券号必须存入数据库或缓存中吗?

阿神
阿神

闭关修行中......

全部回复(3)
洪涛

可以参考算法Bloom Filter

大家讲道理

推荐UUID。

function guid(){
    if (function_exists('com_create_guid')){
        return com_create_guid();
    }else{
        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = chr(123)// "{"
                .substr($charid, 0, 8).$hyphen
                .substr($charid, 8, 4).$hyphen
                .substr($charid,12, 4).$hyphen
                .substr($charid,16, 4).$hyphen
                .substr($charid,20,12)
                .chr(125);// "}"
        return $uuid;
    }
}
小葫芦

额,并不是回到问题,继续追问楼主的第二个问题呢:“这100万张优惠券券号必须存入数据库或缓存中吗?” ,望这方面有经验的大神解惑

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!