Another Decker (another_decker) wrote in php,
Another Decker

Percentage-based outcomes

I'm in need of a program that will take a number as input and use said input to determine the percentage of time it will return true. Just off the top of my head, without looking at google or even the PHP manual, I'm thinking something simple like generating a random number from 1-100 and subtracting the input number from it. The result would then be tested to if it is equal to or less than 0, at which point it would return false - else, it would return true.

Of course, I already see an obvious problem: if looking for say a 99% chance of success, and the random number is anything less than 99 the function would return false and would actually have only a 2% chance of returning true.

Any thoughts a good way to accomplish this?
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.