A
A
AlexaAioGram2021-07-21 16:08:22
Python
AlexaAioGram, 2021-07-21 16:08:22

How to make a chance in python?

I guess I didn’t read the documentation well, but I didn’t find how to make the chances of numbers falling out in python?

For example, so that the number 5 falls out with 80% probability, and the number 7 with 20%

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-07-21
@AlexaAioGram

random.choices([5,7], weights=[80,20], k=1)[0]
Or something similar throughcum_weights

random.choices([5,7], cum_weights=[0.8, 1.0], k=1)[0]

https://docs.python.org/3/library/random.html#rand...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question