Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $coinMultipliers = array('1' => 12, '2' => 12, '3' => 12, '4' => 10, '5' => 10, '6' => 8, '7' => 8, '8' => 6, '10' => 6, '14' => 5, '16' => 4, '18' => 3, '20' => 2, '25' => 1, '30' => 0.7, '150' => 0.3);
- function getRandomCoinMultiplier(array $weightedValues)
- {
- $rand = mt_rand(1, (int) array_sum($weightedValues));
- foreach ($weightedValues as $key => $value) {
- $rand -= $value;
- if ($rand <= 0) {
- return $key;
- }
- }
- }
- // The following FOR-LOOP prints "nothing" when the random selection from above
- // is a FLOAT value.
- for ($i = 0; $i < 1000; $i++) {
- echo getRandomCoinMultiplier($coinMultipliers)."\r\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement