PHP-大转盘礼包概率

// 因为一些敏感信息和词语.上午iteye自动将博客锁定,所以就不多说,这大转盘中间还有一个像时钟的指针的图片就不放上去啦。

大转盘

<?php

class TestAction extends BaseAction{

// 单一礼品概率  http://localhost/index.php/test/getAward

public function getAward()

{

$r =rand(1,100);

$num = 0;

$award_id = 0;

 

$awards['0']['award_name'] = '没有抽中';

$awards['0']['award_pro'] = '0.8';  // 抽中的概率是 80%

$awards['0']['award_card_type'] = '0';

$awards['0']['award_type'] = '0';

 

$awards['1']['award_name'] = '《鬼武者魂》激活码'; 

$awards['1']['award_pro'] = '0.2'; // 抽中的概率是 20%

$awards['1']['award_card_type'] = '1';

$awards['1']['award_type'] = '0';

 

foreach($awards as $k=>$v)

{

$tmp = $num;

$num += $v['award_pro']*100;

if($r>$tmp && $r<=$num)

{

$award_id = $k;

break;

}

}

 

echo '<pre>';

print_r($award_id);

print_r($awards[$award_id]);exit;

 

/*

1

Array

(

[award_name] => 《鬼武者魂》激活码

[award_pro] => 0.2

[award_card_type] => 1

[award_type] => 0

)*/

 

}

 

 

// 多种礼包类型概率(大转盘)   http://test12242013.86joy.com/Activity/index.php/GwzPayLottery

//http://localhost/index.php/test/getAwardsome

public function getAwardsome()

{

$sometypes_award = array(

'award' =>array(

array(

'award_id' => 3796,

'award_name'=>'知石(极)*3',  // 奖品内容

'award_pro' => 0.17,  // 概率

'award_gift_id' => 297,  // 礼包ID

'award_gift_name' => '国庆大转盘(知石)' // 标题

),

array(

'award_id' => 3647,//47  2

'award_name'=>'物语全回复药 * 5', // 奖品内容

'award_pro' => 0.085,// 该礼包概率

'award_gift_id' => 304,  // 礼包ID

'award_gift_name' => '国庆大转盘(物语全回复药)'  // 标题

),

array(

'award_id' => 3700,//100 4

'award_name'=>'万能进化祭品G3 * 1',

'award_pro' => 0.017,

'award_gift_id' => 306,

'award_gift_name' => '国庆大转盘(万能进化祭品)'

),

array(

'award_id' => 3735,//135  5

'award_name'=>'大殊勋宝珠 * 1',

'award_pro' => 0.014,

'award_gift_id' => 307,

'award_gift_name' => '国庆大转盘(大殊勋宝珠)'

),

array(

'award_id' => 3822,//222

'award_name'=>'防石(极)*3',

'award_pro' => 0.17,

'award_gift_id' => 298,

'award_gift_name' => '国庆大转盘(防石)'

),

array(

'award_id' => 3688,//88  3

'award_name'=>'秘传继承护符(魂) * 1',

'award_pro' => 0.051,

'award_gift_id' => 305,

'award_gift_name' => '国庆大转盘(秘传继承护符)'

),

array(

'award_id' => 3908,//308

'award_name'=>'神石(极) * 3',

'award_pro' => 0.059,

'award_gift_id' => 301,

'award_gift_name' => '国庆大转盘(神石)'

),

array(

'award_id' => 3616,//16   1

'award_name'=>'恶鬼全回复药 * 5',

'award_pro' => 0.085,

'award_gift_id' => 303,

'award_gift_name' => '国庆大转盘(恶鬼全回复药)'

),

array(

'award_id' => 3849,//249

'award_name'=>'攻石(极)*3',

'award_pro' => 0.17,

'award_gift_id' => 299,

'award_gift_name' => '国庆大转盘(攻石)'

),

array(

'award_id' => 3885,//285

'award_name'=>'武将强化祭品【藤】 * 9',

'award_pro' => 0.086,

'award_gift_id' => 300,

'award_gift_name' => '国庆大转盘(强化祭品)'

),

array(

'award_id' => 3935,//335

'award_name'=>'內政全回复药 * 5',

'award_pro' => 0.085,

'award_gift_id' => 302,

'award_gift_name' => '国庆大转盘(内政全回复药)'

),

array(

'award_id' => 3760,//160

'award_name'=>'黄魂 * 3000',

'award_pro' => 0.008,

'award_gift_id' => 308,

'award_gift_name' => '国庆大转盘(黄魂)'

),

)

);

 

 

$r =rand(1,100);

$num = 0;

$award_id = 0;

$awards = $sometypes_award['award'];

foreach($awards as $k=>$v)

{

$tmp = $num;

$num += $v['award_pro']*100;

if($r>$tmp && $r<=$num)

{

$award_id = $k;

break;

}

}

 

 

echo '<pre>';

print_r($award_id);

print_r($awards[$award_id]);exit;

/*

8

Array

(

   [award_id] => 3849

   [award_name] => 攻石(极)*3

   [award_pro] => 0.17

   [award_gift_id] => 299

   [award_gift_name] => 国庆大转盘(攻石)

)*/

 

}

 

}

?>

你可能感兴趣的:(php技术总结)