Jump to content

smither07

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Posts posted by smither07

  1. A 20% probability means that you have a 20/100 probability of that happening. You can just pick a random number like mt_rand(1, 100) and declare 20 of them the "positive" choice. Assuming that the output of PHP's PRNG is uniformly distributed, you can simply just choose the lower 20.

     

    Thus, you should be able to do it like this:

    function iCantThinkOfAGoodNameForThisFunction($probability)
    {
        return mt_rand(1, 100) <= $probability;
    }

     

    Then there should be a 20% probability that iCantThinkOfAGoodNameForThisFunction(20) returns true.

     

    It helped me a lot, thanks! :)

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.