Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,692 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.