Complete the code to create a new random number generator using the modern numpy approach.
rng = np.random.[1]()The default_rng() function creates a new random number generator instance in numpy's modern API.
Complete the code to generate 5 random integers between 1 and 10 using the modern numpy random generator.
rng = np.random.default_rng() random_numbers = rng.integers([1], 11, size=5)
The integers(low, high) method generates random integers from low (inclusive) to high (exclusive). To get numbers from 1 to 10, low must be 1 and high 11.
Fix the error in the code to generate 3 random floats between 0 and 1 using the modern numpy random generator.
rng = np.random.default_rng() random_floats = rng.[1](3)
integers() which returns integersrandint() which is not a method of the generator instanceThe random() method generates random floats in [0, 1). The integers() method generates integers, so it is incorrect here.
Fill both blanks to create a random number generator with a fixed seed and generate 4 random integers from 0 to 9.
rng = np.random.[1](12345) numbers = rng.[2](0, 10, size=4)
np.random.seed() which does not return a generatorrandom() instead of integers() for integersUse default_rng(seed) to create a reproducible generator. Then use integers() to generate random integers.
Fill all three blanks to create a dictionary of word lengths for words longer than 3 letters using a comprehension and the modern numpy random generator to shuffle the list.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] rng = np.random.[1]() rng.shuffle(words) lengths = {word: [2] for word in words if len(word) [3] 3}
random() instead of default_rng()< instead of > in the conditionword instead of len(word) for the dictionary valuesCreate the generator with default_rng(). Use len(word) to get word length. Filter words with length greater than 3 using >.