물자 조달, 인재 탐색, 군량 매매시, '랜덤 경험'이 현재 능력치 비중을 따르도록 수정

This commit is contained in:
2018-03-11 22:15:47 +09:00
parent 0a81754f7e
commit 9519a17eaa
2 changed files with 30 additions and 4 deletions
+26
View File
@@ -12,6 +12,32 @@ function randF(){
return mt_rand() / mt_getrandmax();
}
/**
* 값의 비중에 따라 랜덤한 값을 선택
*
* @param array 수치의 비중
*
* @return object 선택된 랜덤 값의 key값. 단순 배열인 경우에는 index
*/
function ChooseRandomItem($items){
$sum = 0;
foreach($items as $value){
$sum += $value;
}
$rd = randF()*$sum;
foreach($items as $key=>$value){
if($rd <= $value){
return $key;
}
$rd -= $value;
}
//fallback. 이곳으로 빠지지 않음
end($items);
return key($items);
}
// 37.5 ~ 75
function abilityRand() {
$total = 150;