In this sample program, you will learn to generate random integer numbers and show the result using the print() function.
To understand this demo program, you should have the basic Python programming knowledge:
In the sample below, we are taking following two inputs from the user and store them in two different variables.
- Total no. of random numbers to generate
- The Upper Limit for the random numbers
To generate random integer numbers, you can use the Python’s random module and one of its function known as the randint().
To generate multiple random numbers, you should call the randint() inside a For Loop.
Sample Code: Generate Random Integer Numbers
# Program to generate random integer numbers # Import Random Module import random count = int(input("How many random numbers do you want to generate? ")) rmax = int(input("Enter Upper Limit for the random numbers: ")) for r in range(count): print(random.randint(0, rmax))
The output of the above code is as follows:
How many random numbers do you want to generate? 10 Enter Upper Limit for the random numbers: 1000 703 153 247 481 971 505 794 589 968 126