Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to NumPy Array Organization Indexing

np.random.RandomState(42)

np.random.RandomState(42) what is seed value and what is random state and why crag use this its confusing

1 Answer

Steven Parker
Steven Parker
229,732 Points

The "seed" is used to initialize the internal pseudo-random number generator. And providing a fixed seed assures that the same series of calls to β€˜RandomState’ methods will always produce the same results, which can be helpful in testing.

The number "42" was apparently chosen as a tribute to the "Hitch-hiker's Guide" books by Douglas Adams, as it was supposedly the answer to the great question of "Life, the universe, and everything" as calculated by a computer (named "Deep Thought") created specifically to solve it.

For more details on the method itself, see the NumPy documentation page for RandomState.