Table of Contents

Python code to generate random phone numbers

 

Python code implementation to generate random phone numbers using the random function

Code: 
import random
def random_phone_num_generator():
    first = str(random.randint(100, 999))
    second = str(random.randint(1, 888)).zfill(3)

    last = (str(random.randint(1, 9998)).zfill(4))
    while last in ['1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888']:
        last = (str(random.randint(1, 9998)).zfill(4))

    return '{}-{}-{}'.format(first, second, last)

n = int(input("Enter Value of n: "))
for i in range(0, n):
    print(random_phone_num_generator())

 

Value of n entered: 100 
Output: The code executed to generate 100 random phone numbers based on the value of n entered by the user.
778-632-2050
322-095-2279
367-834-3793
503-779-1335
595-395-7523
927-123-0137
637-256-1190
979-471-7083
194-849-9476
272-040-1118
954-155-7481
393-724-6870
785-474-4703
403-300-2828
274-424-8961
392-373-2793
724-500-3892
675-688-8654
949-362-5135
798-232-2786
756-410-9578
819-446-3511
253-398-9061
224-161-1338
971-100-5233
129-420-1010
572-210-1026
492-114-2627
156-098-9482
626-212-8372
120-153-8391
766-412-8719
508-219-7532
787-388-0556
101-698-6330
477-669-2130
362-213-4578
276-039-3206
459-781-7184
758-310-2396
882-101-8007
829-706-6554
923-405-1683
255-028-0694
369-317-7827
608-579-4631
267-519-0311
703-332-7942
577-322-9301
620-197-5384
579-710-1702
743-100-7475
717-309-2088
662-280-3502
330-535-5142
269-874-1891
759-284-4139
889-186-7947
839-299-8495
286-166-0174
941-521-3962
651-081-8013
851-610-2145
658-867-1372
279-879-8162
936-141-2152
785-757-3357
600-354-3893
140-643-3902
766-173-6010
873-547-9372
720-205-9433
221-055-5126
872-811-7652
776-151-0175
947-043-8115
252-752-8684
114-005-6251
637-362-7799
434-770-2203
370-373-3009
231-505-9116
347-273-6608
462-188-6288
551-791-2147
608-411-0557
517-318-0304
134-408-0541
683-030-7677
302-245-4250
634-339-7428
236-768-6686
712-478-1102
793-102-4080
394-714-7042
589-642-9626
974-798-6001
427-583-7242
402-183-3268
740-169-0242