Ad

A Question About "randoms And My Question"

- 1 answer

example:

import random
random.seed(10)
n1=random.randint(1,5)
n2=random.randint(1,5)
print(n1,n2)  # => 5,1

I am not good at English, so I used a translator. Please understand if it's awkward.

If there is the same number in parentheses behind the 'seed' in the same expression, does the value always come out the same? I wonder what the numbers in parentheses do. Run a no number expression multiple times, the value change all the time.

똑같은 식에서 seed 뒤의 괄호 안에 같은 숫자가 들어가면 값도 무조건 똑같이 나오나요? 괄호 안에 들어가는 숫자가 무슨 역할을 하는지 궁금합니다. 숫자를 넣지 않은 식에서는 여러번 실행하면 값이 계속 바뀝니다.

Ad

Answer

Given two random instances within the same seed, the nth call to randint on the first instance will yield the same number as the nth call on the second instance.

That does not mean that the random value returned across multiple calls for the same instance will be the same.

You will see the same ordered series of values, meaning if you were to run your python program at some different time, you would see the output 5,1 once again.

Ad
source: stackoverflow.com
Ad