[Python] random.choices() in python

Discussão em 'Python' iniciado por Stack, Junho 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'd like to confirm that

    a = [random.choices([0,1],weights=[0.2,0.8],k=1) for i in range(0,10)]


    does probabilistically the same thing as

    a = random.choices([0,1],weights=[0.2,0.8],k=10)


    In particular, I expect both to make 10 independent draws from the set {0,1} with probability 0.2 on 0 and 0.8 on 1. Is this right?

    Thanks!

    Continue reading...

Compartilhe esta Página