<commit_before>""" How to generate a random 4 digit number not starting with 0 and having unique digits in python? """

import random
l = [0,1,2,3,4,5,6,7,8,9]
random.shuffle(l)
if l[0] == 0:
    print(''.join(map(str, l[1:5])))
else:
    print(''.join(map(str, l[0:4])))<commit_msg>Fix of shuffle. There should be random swap of leading zero with one from nine (non-zero) positions.<commit_after>""" How to generate a random 4 digit number not starting with 0 and having unique digits in python? """

import random

# 1.
l = [0,1,2,3,4,5,6,7,8,9]
random.shuffle(l)
if l[0] == 0:
    pos = random.choice(range(1, len(l)))
    l[0], l[pos] = l[pos], l[0]
print(''.join(map(str, l[0:4])))

# 2.
# We create a set of digits: {0, 1, .... 9}
digits = set(range(10))
# We generate a random integer, 1 <= first <= 9
first = random.randint(1, 9)
# We remove it from our set, then take a sample of
# 3 distinct elements from the remaining values
last_3 = random.sample(digits - {first}, 3)
print(str(first) + ''.join(map(str, last_3)))

# 3.
numbers = [0]
while numbers[0] == 0:
    numbers = random.sample(range(10), 4)
print(''.join(map(str, numbers)))

{'fraction_non_alphanumeric': 0.17975567190226877, 'fraction_numerical': 0.05148342059336824, 'mean_word_length': 4.285714285714286, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1395936', 'n_tokens_mistral': 456, 'n_tokens_neox': 429, 'n_words': 143}