Q:

How to generate random number from desired range using python

i have a list with 9000 list items  as strings,  i want to select 4000 instances randomly amongst them. how can i achieve this.
 I have write down a code. 
from random import randint
for r in range(9000):
    print(randint(9000))

first i will generate the random 4000 random number
and then list members will be picked up by the selected random numbers 
I have write down a code which is showing an error code is as given bellow

A:

use random.sample
from random import sample

my_list = [1,2,3,4,5,5,4]

print(sample((my_list), 5)) # you would change 5 to 4000

As a side note If you want to remove duplicates from your result you can use a set as sets in python don't allow duplicate items, another example
my_list = [1, 2, 3, 4, 5, 5, 4, 6, 5, 3, 2, 12]

result = set(sample((my_list), 5)) # you would change 5 to 4000
print(result)

#set might remove duplicates so you wont have the desired number of items again
while len(result) < 5: # length of your list
    rand = choice(my_list)
    result.add(rand)

print(result)

