samedi 27 juillet 2019

How to get a randomized list but a constant result each time when operated

I have a list of string, and I want its elements randomly shuffled. But in the meantime, I also want that would be the same result unless change demanded.

I thought random.seed() is gonna help. So I tried this,

random.seed(30)
random.shuffle(a)

say a is a list of strings. But each time I couldn't get the same result.

But in numpy so would tackle my problem

np.random.seed(30)
np.random.randint(0, 10)

That returns the same int. Oddly enough, when I tried this,

np.random.seed(30)
np.random.shuffle(a)

, that doesn't return the same result.
What's the trick here? Thanks!!!!




Aucun commentaire:

Enregistrer un commentaire