Question: You can use the random module's seed function to seed the random - number generator yourself this forces randrange to begin calculating its pseudorandom number

You can use the random module's seed function to seed the random-number generator yourselfthis forces randrange to begin calculating its pseudorandom number sequence from the seed you specify. Choosing the same seed will cause the random number generator to generate the same sequence of random numbers.
In the following session, snippets [2] and [5] produce the same results purely by coincidence:
In [1]: random.seed(32)
In [2]: for roll in range(10):
...: print(random.randrange(1,7), end='')
...:
1223624161
In [3]: for roll in range(10):
...: print(random.randrange(1,7), end='')
...:
1353156435
In [4]: random.seed(32)
In [5]: for roll in range(10):
...: print(random.randrange(1,7), end='')
...:
1223624161
When you're debugging logic errors in programs that use randomly generated data, it can be helpful to use the same sequence of random numbers until you've eliminated the logic errors, before testing the program with other values.
Function randrange actually generates pseudorandom numbers, based on an internal calculation that begins with a numeric value known as a seed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!