import random


def randLines(file, n):
    """
    Grabs n random lines in a file using Algorithm R.
    """
    lines = []
    for num, line in enumerate(file):
        if num < n:
            lines.append(line)
        else:
            randNum = random.randrange(0, num)
            if randNum < n:
                lines[randNum] = line
    return lines