欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

基于时间随机返回比率的随机值

程序员文章站 2022-04-27 08:20:52
...

无详细内容 $config = array( 'sohu' = 10, 'sina' = 30, 'qq' = 20, 'baidu' = 20,);echo randomBaseTimestamp($config);function randomBaseTimestamp($data = array()) { uasort($data, function ($a, $b) { return rand(-1, 1); }); $time = time(); $to

$config = array(
    'sohu' => 10,
    'sina' => 30,
    'qq' => 20,
    'baidu' => 20,
);

echo randomBaseTimestamp($config);

function randomBaseTimestamp($data = array()) {
    uasort($data, function ($a, $b) {
        return rand(-1, 1);
    });
    $time = time();
    $total = array_sum($data);
    $mod = $time%$total;
    $result = '';
    foreach($data as $k => $v) {
        $result = $k;
        $mod -= $v;
        if($mod