vendredi 23 mars 2018

How is random state updated after calling np.random.shuffle()? and how is it impacted by the length of the list to be shuffled?

How is the random state updated after calling np.random.shuffle()? and how is it impacted by the length of the list to be shuffled?

Here is the experiment:

np.random.seed(3)
print(np.random.get_state()[0],str(np.random.get_state()[1][:5]))
delta = 7
for t in [3,7,8, 9, 10]:
    print('-'*20)
    x = np.power(2, t)
    np.random.seed(3)
    a =np.arange(x-delta)
    np.random.shuffle(a)
    print(x-delta, np.random.get_state()[0],str(np.random.get_state()[1][:5]))
    np.random.seed(3)
    a =np.arange(x)
    np.random.shuffle(a)
    print(x, np.random.get_state()[0],str(np.random.get_state()[1][:5]))
    np.random.seed(3)
    a =np.arange(x+delta)
    np.random.shuffle(a)
    print(x+delta, np.random.get_state()[0],str(np.random.get_state()[1][:5]))

and the result:

MT19937 [         3 1142332464 3889748055 3734916391 3619205944]
--------------------
1 MT19937 [         3 1142332464 3889748055 3734916391 3619205944]
8 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
15 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
--------------------
121 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
128 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
135 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
--------------------
249 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
256 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
263 MT19937 [2266350226  522119106 3046352735  732669494 2548320174]
--------------------
505 MT19937 [3210938781 3041878801 2995991318 2989044749 4131327847]
512 MT19937 [3210938781 3041878801 2995991318 2989044749 4131327847]
519 MT19937 [3210938781 3041878801 2995991318 2989044749 4131327847]
--------------------
1017 MT19937 [2643427254 2135041851 1650564992  768318449  937622320]
1024 MT19937 [2643427254 2135041851 1650564992  768318449  937622320]
1031 MT19937 [2643427254 2135041851 1650564992  768318449  937622320]

Thank you very much.




Aucun commentaire:

Enregistrer un commentaire