In this simple python program, we need to generate random numbers. It's a beginner-level python program.
To understand this example, you should have knowledge of the following Python programming topics:
This python program is to generate a random number between a range. For example, if we want to generate a random number between 100 and 500. We have to use this simple python program. Here we use a random module, which is a built-in module in python to generate random numbers between a range of numbers. The Random module has many methods like
And a lot more. Here we can use the method
randrange() which is used to generate the random numbers in the given range. So in this beginner python program, we accept the number range( here we use a predefined number range) and import the module randomly. Finally, print the result using the
STEP 1: Import the in-built module called random, used in python to generate a random number.
STEP 2: Use the random module with int to generate the values between some ranges. We can also accept those values from the user.
STEP 3: Print the generated number using the print statement in python.
import random print(random.randint(100,500))