import random
import string


def random_mutate(word, mutations, no_punct, alpha):
    """Randomly mutate the word with 'mutations' frequency.
       If no_punct is true, leave punctuation unaltered."""

    letters = list(word)  # split the current word in a list
    num_mutations = round(mutations * len(letters))
    indexes = random.sample(range(len(letters)), num_mutations)
    for j in indexes:  # mutate the selected letters
        if no_punct and letters[j] in string.punctuation:
            continue
        letters[j] = random.choice(alpha.replace(letters[j], ''))

    return ''.join(letters)