import random


def randcolor(mode):
    """Makes a random color for the given mode"""
    ri = lambda v: random.randint(0, v)
    if mode == 'L':
        return ri(255)
    elif mode == '1':
        return ri(1)
    elif mode == 'I':
        return ri(2**23-1)
    elif mode == 'F':
        return random.random()
    elif mode == 'RGB':
        return (ri(255), ri(255), ri(255))
    elif mode == 'RGBA':
        return (ri(255), ri(255), ri(255), ri(255))
    else:
        assert 1 == 0, 'invalid mode %s' % (mode)