Generation

generate functionMon, 26 Dec 2022

Write a function that takes length as an argument and generates a random sequence of digits of length, with at least one digit 3 and one digit 7 in the sequence. The positions of 3 and 7 must be determined randomly. For example: "456379" or "033456127".

def rand_seq(length): import random seq = "" while True: if "3" in seq and "7" in seq: break seq = "".join([str(random.randint(0, 9)) for num in range(length)]) return seq rand_seq(15)

Questions about programming?Chat with your personal AI assistant