Random number generator with triangular distribution
Implement a random number generator with triangular probability dristribution. Input parameters are: minimum, most likely, maximum
Blueprint information
- Status:
- Complete
- Approver:
- Michael-Olaf
- Priority:
- Essential
- Drafter:
- Michael-Olaf
- Direction:
- Approved
- Assignee:
- Michael-Olaf
- Definition:
- Approved
- Series goal:
- Accepted for trunk
- Implementation:
- Implemented
- Milestone target:
- 0.3
- Started by
- Michael-Olaf
- Completed by
- Michael-Olaf
Related branches
Related bugs
Bug #350310: Triangular distribution is not even enough | New |
Bug #351250: Triangular distribution does not work if the most likely value is not in the middle | Fix Released |
Sprints
Whiteboard
Following the code for such a random generator:
private static function triangular(
$u=
if ($u <= ($most-
} else {
}
return $r;
}
Alternative algorithm 1 (does not work if the most likely value is not in the middle):
private static function triangular(
$pmin = $p*2 - $m;
$omax = $o*2 - $m;
$y = 0;
if($pmin < 0){
$y = $pmin * -1;
}
$rp = (rand()
$ro = (rand()
$result = ($rp + $ro)/2;
$result -= $y;
return $result;
}
Alternative algorithm 2:
private static function triangular(
$side = rand()/
$border = ($m-$p)/($o-$p);
if($side < $border){
$r1 = (rand()
$r2 = (rand()
$result = max($r1,$r2);
}else{
$r1 = (rand()
$r2 = (rand()
$result = min($r1,$r2);
}
return $result;
}