Friday, January 16, 2026
HomeLanguagesHow to generate a random phone number using Python?

How to generate a random phone number using Python?

In this article, we will learn how to generate a random phone number using Python. In general, Indian phone numbers are of 10 digits and start with 9, 8, 7, or 6.

Approach:

  • We will use the random library to generate random numbers.
  • The number should contain 10 digits.
  • The first digit should start with 9 or 8 or 7 or 6, we will use randint() method.
  • The remaining 9 digits will also be generated using the randint() method.

Examples:

The generated random phone numbers would looklike:
9980231467
8726189362

Implementation:

Python3




# import module
import random as r
  
ph_no = []
  
# the first number should be in the range of 6 to 9
ph_no.append(r.randint(6, 9))
  
# the for loop is used to append the other 9 numbers.
# the other 9 numbers can be in the range of 0 to 9.
for i in range(1, 10):
    ph_no.append(r.randint(0, 9))
  
# printing the number
for i in ph_no:
    print(i, end="")


Output:

8349603502
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32470 POSTS0 COMMENTS
Milvus
117 POSTS0 COMMENTS
Nango Kala
6837 POSTS0 COMMENTS
Nicole Veronica
11972 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12052 POSTS0 COMMENTS
Shaida Kate Naidoo
6972 POSTS0 COMMENTS
Ted Musemwa
7211 POSTS0 COMMENTS
Thapelo Manthata
6925 POSTS0 COMMENTS
Umr Jansen
6904 POSTS0 COMMENTS