So i want to make a list that stores random numbers but the random numbers stored in that list should be unique i have tried writing the program in so many ways but they havent worked i tried sorting the list in ascending order and then look for duplicates and change their values(didnt work)
This is the code i wrote, This code assigns the random value and checks for duplicates while doing that and assigns them a new random value but i still get duplicates:
import random
random_list=[]
for j in range(0,11):
random_list.append(random.randint(0,11))
for i in range(0,j):
while random_list[i]== random_list[j]:
random_list[i]=random.randint(0,11)
random_list.sort()
print(random_list)
What I have tried:
I have tried doing a thorough dry run through the program but i cant figure out why it doesnt work
import random
random_list=[]
for j in range(0,4):
random_list.append(random.randint(1,4))
print("Before: ", random_list)
for i in range(0,j):
while random_list[i]== random_list[j]:
random_list[i]=random.randint(1,4)
print("After: ",random_list)
random_list.sort()
print(random_list)