Python Random Numbers Generation

By | July 30, 2022

The process of Python Random Numbers Generation is very simple and easy to understand.

Steps To Generate a Random Number in Python

Just follow these steps:

Random Number Generation in Python Programming

1. Import random module

2. Use randint() method of random module to generate an integer number within a specific range.

Example: Generate a Random Number Between 1 and 50

 

import random
n = random.randint(1,50);
print(n)

Output

44

Python Program To Generate 20 Random numbers in range of 1 to 10

We will use a for loop to generate 20 random numbers. The for loop will use the range(1,21) function for 20 iterations.

# Python program to generate 5 random numbers between 1 and 10

import random
num_list = []
for i in range(1,21):
    n = random.randint(1,10);
    num_list.append(n)
    
print("5 Random numbers between 1 to 10 are:")
print(num_list)

Output

20 Random numbers between 1 to 10 are:
[2, 4, 4, 1, 4, 9, 4, 9, 8, 9, 7, 6, 6, 7, 9, 10, 5, 9, 9, 2]

You may also like:

Python GUI ( Graphcal User Interface ) Programs using tkinter Module

New arrivals programs / tutorials / articles/ Updates on easycodebook.com Python GUI ( Graphcal User Interface ) Programs using tkinter Module
  1. Find Factorial by Recursive Function Python GUI Program
  2. Multiplication Table Python GUI Program
  3. Python GUI Program Area of Triangle with base and height
  4. Python GUI Temperature Conversion Program Celsius to Fahrenhiet
  5. Python GUI Program Temperature Conversion Fahrenheit to Celsius
  6. Python Pounds to Kilogram Converter GUI tkinter Program
  7. Python 3 Four Function Calculator Program tkinter GUI
  8. Python Digital Clock Program using tkinter GUI
  9. Python Quotes Changer Program tkinter GUI
  10. Python 3 tkinter Spinbox GUI Program Example
  11. Python 3 tkinter Message Widget Program Examples
  12. Python 3 GUI Program tkinter Radio Buttons
  13. Adding Menus to Python 3 tkinter GUI Programs
  14. Python 3 GUI Program Add Two Numbers
  15. Explain Python grid Geometry Manager with Example Code
  16. Python 3 GUI Miles to Kilometers Converter tkinter Program
  17. Python 3 tkinter GUI Kilogram to Pounds Program
  18. Python Set Label Text on Button Click tkinter GUI Program
  19. Show Label and Button Widgets Python Tkinter Program
  20. Python 3 Tkinter GUI Hello World Program
  21. Create and Show Root Window of tkinter GUI Program

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *