This works almost fine but the number starts with 0 sometimes:
import random
numbers = random.sample(range(10), 4)
print(\'\'.join(map(str, numbers)))
This is very similar to the other answers but instead of sample or shuffle you could draw a random integer in the range 1000-9999 until you get one that contains only unique digits:
import random
val = 0 # initial value - so the while loop is entered.
while len(set(str(val))) != 4: # check if it's duplicate free
val = random.randint(1000, 9999)
print(val)
As @Claudio pointed out in the comments the range actually only needs to be 1023 - 9876 because the values outside that range contain duplicate digits.
Generally random.randint will be much faster than random.shuffle or random.choice so even if it's more likely one needs to draw multiple times (as pointed out by @karakfa) it's up to 3 times faster than any shuffle, choice approach that also needs to join the single digits.