-1

I readed really a lot forums and problems here, but cant find the right solution.

So, most of you (I hope) know freebitco.in, you can win bitcoins every 1 hour. There is the following table. If you roll a number between 0-9885 you will get the following payout and etc.. But there is a very very little chance to roll number bigger than 9885. For example the change to get number bigger than 9885 is 5%, bigger than 9985 - 1%, bigger than 9993 - 0.001%, 10k - impossible. So, how I can have a script like this?

enter image description here

2 Answers2

1

You don't need to influence rand(), just get a random number and test its value against the ranges.

$val = mt_rand(0, 10000);
if ($val <= 9885) {
    $payout = 0.00000035;
} elseif ($val <= 9985) {
    $payout = 0.00000351;
} elseif ($val <= 9993) {
    $payout = 0.00003515;
} ...
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • What do you mean? You don't want equal probability for all numbers? The whole point of this is that the bigger payouts should be less frequent. – Barmar May 06 '19 at 23:36
  • It should be `0-9885` 98.85% of the time, `9886-9985` should be 1%, `9986-9993` should be `0.08%`, etc. – Barmar May 06 '19 at 23:38
  • If you want different percentages, you should use different number ranges. E.g. if you want the lowest payout to be 95%, it should be the range 0-9500. – Barmar May 06 '19 at 23:40
  • Maybe see https://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice – Barmar May 07 '19 at 13:43
0

I'm not sure how you would like to calculate the winner. However, you might just want to design an array, and use a random number and lookup in the array.

You might not want to have anymore probabilities, but if you like so, you can just add as an attribute in the array, then do any math you wish in the if statement or else.

$lookup = array(
    "0" => array(
        "luck" => 9885,
        "payout" => 0.00000035,
        "probability" => 0.5,
    ),
    "1" => array(
        "luck" => 9886,
        "payout" => 0.00000351,
        "probability" => 0.3,
    ),
    "2" => array(
        "luck" => 9993,
        "payout" => 0.00003515,
        "probability" => 0.1,
    ),
    "3" => array(
        "luck" => 9997,
        "payout" => 0.00035149,
        "probability" => 0.09,
    ),
    "4" => array(
        "luck" => 9999,
        "payout" => 0.00351494,
        "probability" => 0.009,
    ),
    "5" => array(
        "luck" => 9999,
        "payout" => 0.03514939,
        "probability" => 0.001,
    ),
);

BitocoinPayout(mt_rand(0, 10000), $lookup);

function BitocoinPayout($luck_number, $lookup)
{

    foreach ($lookup as $value) {
        if ((int) $luck_number < (int) $value["luck"]) {
            // or do other math
            echo "YAAAY! You just won Stephanie Kostova's jackpot of " . $value["payout"] . " Bitcoin! ";
            break;
        } else {
            continue;
            // or do other math
        }
    }
}

Output

YAAAY! You just won Stephanie Kostova's jackpot of 3.5E-7 Bitcoin!
Emma
  • 27,428
  • 11
  • 44
  • 69