1

Calculation to  work with

So I'm working on a "chest opening simulator" with a client of mine and I have completed the whole system except for the actual probability part.

He sent me this calculation and algorithm for how the different rarities and items should function.

Now I got completely stuck here, but from looking at this logic, if I roll a dice that is 1-100, and it lands on 2, I hit the "Super Rare" tier correct?

I made a function for rolling a dice that is between 0.00-100.00 and which is provably fair (Using a users Client seed and a random server seed + nonce for each roll) which you can find below, how would I utilize this function to determine which of the tiers I hit and what item within the tier?

public function roll()
{
  $client_seed = "client_seed";
  $server_seed = "server_seed";
  $nonce = 0;
  $secret = $client_seed."-".$nonce;
  $hash = hash_hmac('sha512', $secret, $server_seed); // Hash server_seed and secret

  for($i = 0; $i < strlen($hash); $i += 5)
  {
      $sub = substr($hash, $i, 5); //Split it
      if(strlen($sub) == 5)
      {
          $decimal_number = hexdec($sub); // Hex to decimal. At this point we have a random number

          if($decimal_number < 1000000)
          {
              $decimal_fourc = bcmod($decimal_number, 10000); //Get the modulus
              $final_decimal = bcdiv($decimal_fourc, 100, 2); //Divide the result by 100
                  $obj = new \stdClass();
                  $obj->seeds = new \stdClass();
                      $obj->seeds->server = $server_seed;
                      $obj->seeds->client = $client_seed;
                  $obj->result = new \stdClass();
                      $obj->result->nonce = $nonce;
                      $obj->result->lucky_number = number_format($final_decimal, 2);

          }
      } else {
          break;
      }
  }

  echo "<pre>";
  print_r($obj);
  echo "</pre>";
}
Edwin
  • 51
  • 1
  • 7

0 Answers0