Professional Documents
Culture Documents
Python Random
Python Random
import random
import string
def generate_sequence(pattern):
"""
Generates a random sequence of letters and numbers following the given pattern.
Args:
pattern: A string representing the pattern, where "l" indicates a letter and
"n" indicates a number.
Returns:
A string containing the generated sequence.
"""
sequence = ""
for char in pattern:
if char == "l":
sequence += random.choice(string.ascii_lowercase)
elif char == "n":
sequence += str(random.randint(0, 9))
return sequence
Explanation:
This code will generate 1000 sequences of random letters and numbers following the
specified pattern. The length of each sequence will be 12 characters due to the
pattern "l,n,l,l,n,l,n,n,l,n,n,l".