Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i make something have like a 20% chance to happen in Python? [duplicate]

Tags:

python

The name about sums it up, thanks guys. (Just to make it more specific I'm programming stats and I want to have a certain chance that a stat will raise every time you level up)

like image 550
Tyler The Hero Avatar asked Oct 28 '25 16:10

Tyler The Hero


1 Answers

You can use random to get a random value between 0 and 1, and compare it to 0,2. Like this:

import random
if random.random() < 0.2:
    do_something()
like image 67
Simon Lindblad Avatar answered Oct 30 '25 07:10

Simon Lindblad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!