import random


def _get_random_words(filename, n_words):
    """Given a # of words, return that many random words from the file 'filename'.

    If n_words > the number of words in the file, there will be duplicates in the list.

    This is a utililty function for get_random_arabic_citizen_names() and
    get_random_arabic_place_names().
    """
    words = open(filename, 'rb').read().decode('utf-8')
    # Remove blank lines and extraneous whitespace.
    words = [word.strip() for word in words.split('\n') if word.strip()]

    # There's only 267 names in that file and the caller may have asked for more which will
    # cause an error when random.sample() is called. I make sure I have enough n_names before I
    # call sample().
    while len(words) < n_words:
        words = words + words

    return random.sample(words, n_words)