close

[Solved] Name: name ‘random’ is not defined

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Name: name ‘random’ is not defined in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Name: name ‘random’ is not defined Error Occurs?

Today I get the following error Name: name ‘random’ is not defined in python.

How To Solve Name: name ‘random’ is not defined Error ?

  1. How To Solve Name: name 'random' is not defined Error ?

    To Solve Name: name 'random' is not defined Error you need to import the random library with the import keyword

  2. Name: name 'random' is not defined

    To Solve Name: name 'random' is not defined Error you need to import the random library with the import keyword

Solution 1

You have to import the module random:

import random

r = random.randint(1,10)
# ...

Solution 2

you need to import the random library with the import keyword

import random 
random.randint(1,10)    #no. between 0 and 10

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read