import random
import collections


def expand_words_from_counts(word_counts: dict[str, int]) -> tuple[dict[str, int], list[str]]:
    """Expand words using their counts to a list of words in randomized order."""
    expanded_words = [word for word, count in word_counts.items() for _ in range(count)]
    random.shuffle(expanded_words)

    # We need the case insensitive counts to compare against.
    case_insensitive_counts = collections.defaultdict(int)
    for word, count in word_counts.items():
        case_insensitive_counts[word.lower()] += count

    return case_insensitive_counts, expanded_words