Apr-04-2023, 03:20 PM
this is an approach how the task could be done.
it uses random.choises(...) to generate 4 numbers out of a range.
to check if the first 2 numbers match, it uses a slice.
it uses random.choises(...) to generate 4 numbers out of a range.
to check if the first 2 numbers match, it uses a slice.
from random import choices target_start = [1,2] nums_count = 4 while True: gen_nums = choices(range(0, 10), k=nums_count) if gen_nums[:2] == target_start: print(gen_nums) break