Answered step by step
Verified Expert Solution
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 randomnumber 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 and produce the same results purely by coincidence:
In : random.seed
In : for roll in range:
: printrandomrandrange end
:
In : for roll in range:
: printrandomrandrange end
:
In : random.seed
In : for roll in range:
: printrandomrandrange end
:
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started