[Python] Python Random choice same sequence when start up the program [closed]

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

  1. Stack

    Stack Membro Participativo

    When starting the python program with using random choice, I always get this 1, 1, 3 ,2... outputs. Is it expected? What is a good work around so when starting python again it gives different number (Am thinking to use time as variable, but maybe there is a ready made solution)

    python3

    import random
    # random.seed(40)
    list = [1,2,3,4,5]

    >>> print(random.choice(list))
    1
    >>> print(random.choice(list))
    1
    >>> print(random.choice(list))
    3
    >>> print(random.choice(list))
    2
    >>> print(random.choice(list))
    2
    >>> print(random.choice(list))
    2

    Continue reading...

Compartilhe esta Página