0
0
NumPydata~10 mins

Integer random with integers() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Integer Random Numbers with numpy.integers()
📖 Scenario: You are working on a simple data science task where you need to generate random integer data for analysis. This is common when simulating data or testing algorithms.
🎯 Goal: Learn how to use numpy.random.Generator.integers() to create random integers within a specific range.
📋 What You'll Learn
Create a numpy random Generator instance
Generate random integers between 10 and 20
Generate exactly 5 random integers
Print the generated random integers
💡 Why This Matters
🌍 Real World
Generating random integers is useful in simulations, testing algorithms, and creating sample datasets.
💼 Career
Data scientists often need to create random data for experiments and model testing.
Progress0 / 4 steps
1
Create a numpy random Generator instance
Import numpy as np and create a random number generator instance called rng using np.random.default_rng().
NumPy
Need a hint?

Use np.random.default_rng() to create the generator.

2
Set the range for random integers
Create two variables called low and high and set them to 10 and 20 respectively. These will define the range for the random integers.
NumPy
Need a hint?

Assign 10 to low and 20 to high.

3
Generate 5 random integers between low and high
Use the integers() method of rng to generate 5 random integers between low (inclusive) and high (exclusive). Store the result in a variable called random_numbers.
NumPy
Need a hint?

Use rng.integers(low, high, size=5) to generate the numbers.

4
Print the generated random integers
Print the variable random_numbers to display the generated random integers.
NumPy
Need a hint?

Use print(random_numbers) to show the array.