Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago