Question: Generate a random number between low and high. Part 2: In a seperate f
ID: 3619699 • Letter: Q
Question
Question: Generate a random number between low and high.Part 2: In a seperate file, generate a random integer between
low and high, including both end points.
--
The reading for the question is below:
---
Random numbers:
Most computer programs do the same thing every time they execute, so they are
said to be deterministic. Determinism is usually a good thing, since we expect
the same calculation to yield the same result. For some applications, though, we
want the computer to be unpredictable. Games are an obvious example, but there
are more.
Making a program truly nondeterministic turns out to be not so easy, but there
are ways to make it at least seem nondeterministic. One of them is to generate
random numbers and use them to determine the outcome of the program. Python
provides a built-in function that generates pseudorandom numbers, which are
not truly random in the mathematical sense, but for our purposes they will do. The random module contains a function called random that returns a floating-point
number between 0.0 and 1.0. Each time you call random, you get the next number
in a long series. To see a sample, run this loop:
import random
for i in range(10):
x = random.random()
print x
To generate a random number between 0.0 and an upper bound like high, multiply
x by high. Question: Generate a random number between low and high.
Part 2: In a seperate file, generate a random integer between
low and high, including both end points.
--
The reading for the question is below:
---
Random numbers:
Most computer programs do the same thing every time they execute, so they are
said to be deterministic. Determinism is usually a good thing, since we expect
the same calculation to yield the same result. For some applications, though, we
want the computer to be unpredictable. Games are an obvious example, but there
are more.
Making a program truly nondeterministic turns out to be not so easy, but there
are ways to make it at least seem nondeterministic. One of them is to generate
random numbers and use them to determine the outcome of the program. Python
provides a built-in function that generates pseudorandom numbers, which are
not truly random in the mathematical sense, but for our purposes they will do. The random module contains a function called random that returns a floating-point
number between 0.0 and 1.0. Each time you call random, you get the next number
in a long series. To see a sample, run this loop:
import random
for i in range(10):
x = random.random()
print x
To generate a random number between 0.0 and an upper bound like high, multiply
x by high.
Explanation / Answer
Dear, As random class random function Return the next random floating point number in the range [0.0, 1.0). In order to generate numbers between low and high we use random class uniform function with two parameter specified i.e low, high Example: if low is 1 and high is 10 random.uniform(1, 10) Code to generate 10 random numbers with 0.0as low and high 1.0 import random for i in range(10): x = random.uniform(0.0,1.0) print x Hope this will help you..
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.