Recall & Review
beginner
What does
numpy.random.Generator.integers() do?It generates random integers from a specified range, similar to picking random numbers from a hat between a low and high value.
Click to reveal answer
beginner
What parameters are needed for
integers() to generate random numbers?You need to provide
low (start of range), high (end of range, exclusive), and optionally size (how many numbers to generate).Click to reveal answer
intermediate
How is
integers() different from randint() in NumPy?integers() is part of the new random Generator API, offering better performance and features, while randint() is from the older RandomState API.Click to reveal answer
beginner
What happens if you set
size=None in integers()?It returns a single random integer instead of an array of integers.
Click to reveal answer
intermediate
Why is it better to use
numpy.random.default_rng().integers() over older random functions?Because it uses a newer, more reliable random number generator that is faster and has better statistical properties.
Click to reveal answer
Which parameter in
integers() defines the upper limit (exclusive) of the random numbers?✗ Incorrect
The
high parameter sets the exclusive upper bound for the random integers.What does
size=5 do in integers(low=0, high=10, size=5)?✗ Incorrect
The
size parameter controls how many random integers are generated.What is the default behavior if
size is not specified in integers()?✗ Incorrect
If
size is None, integers() returns a single integer.Which of these is the correct way to create a random integer generator in NumPy?
✗ Incorrect
default_rng() creates a new Generator object, which then can use integers().If you want random integers between 1 and 10 inclusive, which
integers() call is correct?✗ Incorrect
The
high parameter is exclusive, so to include 10, set high=11.Explain how to generate 3 random integers between 5 and 15 using NumPy's
integers().Remember the upper bound is exclusive, so add 1 to include 15.
You got /3 concepts.
Describe the advantages of using
integers() from the new Generator API over older random integer functions.Think about reliability and speed improvements.
You got /4 concepts.