0

I start with the premise that this question has probably already been asked, but either in the last 2/3 hours that I try I have not seen it, or it was not exactly what I was looking for. So if it was a duplicate, please also report the question as a duplicate. To explain simply what I'm looking for, I explain with a very simple example:

"Nicholas has to go to the office. He has a percentage chance of being able to go to the office. The percentage varies according to external conditions. If Nicholas falls within that percentage, then he manages to go to the office"

Mine is a stupid example, but I wanted to simplify my request. My percentage value starts from 4.167% and increases or decreases based on external factors (reconnecting to the example, the road conditions could increase or decrease the percentage of probability that Nicholas will go to the office). In practice, my script has an action it must perform with a probability of success or failure (as if it were a random chess move) and the percentage is the probability that this action takes place or not. If the script fails (Nicholas can't get to the office), the script continues with the rest. If the script succeeds (Nicholas manages to go to the office) perform that action and then continue with the rest. So, I ask, how do I set up what I ask for to happen? That is, how do I do this check to know if, precisely, given the percentage, the script can perform that action or not? Since I know almost nothing about probability, except the basics, I hope I made myself understood better. Ask for further clarification. Thanks for your help.

BlackFenix06
  • 577
  • 1
  • 6
  • 22
  • 3
    Does this answer your question? [True or false output based on a probability](https://stackoverflow.com/questions/5886987/true-or-false-output-based-on-a-probability) – Flux Jan 05 '20 at 23:27
  • Yes, theoretically yes. At least I think so. "random.random ()" arbitrarily chooses a number between "0.0" (included) and 1.0 (excluded). So I should turn my percentage into a float number (0.4167) and put a condition in which the comparison between the random number and the threshold is made. If the number is less, then the script is successful. If higher then it fails. Quite right? – BlackFenix06 Jan 05 '20 at 23:41
  • If the probability of success (i.e. being able to go to the office) is 0.95833 (i.e. 1 - 0.04167), then just check whether or not `decision(0.95833)` returns `True`. If `True` is returned, then Nicholas was able to go to the office. – Flux Jan 05 '20 at 23:55
  • Okay, thanks for the explanation. So that's what I was looking for. Thank you. – BlackFenix06 Jan 06 '20 at 00:00

0 Answers0