D
D
Dumba2021-08-31 20:28:25
Python
Dumba, 2021-08-31 20:28:25

How to make a team with a "chance"?

Need code for discord bot. A command that, with some chance, will produce a different answer. For example:

if message.content.startswith('$lol'):
        await message.channel.send(f' {message.author.mention} lil')

but with a chance of (let's say) 0.0001 it will give a different answer than lil.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-08-31
@Dumba

https://docs.python.org/3/library/random.html?high...

>>> import random
>>> 
>>> vars = ['yes', 'no']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['no']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>> random.choices(vars, weights=[0.9, 0.1])
['yes']
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question