import random
import colorsys


def color_for(hash_code, color_dict):
    """
    Get a color for a specific 'hash code' by either taking one we've already recorded for this hash code,
    or generating a new random one.
    """
    # do we have it already?
    if hash_code in color_dict:
        # yes, job done
        return color_dict[hash_code]
    else:
        # no, generate one
        hue = random.random()
        sat = 0.9 + random.random() * 0.1
        rgb = colorsys.hsv_to_rgb(hue, sat, 0.9)
        r = int(rgb[0] * 255)
        g = int(rgb[1] * 255)
        b = int(rgb[2] * 255)
        new_col = (r, g, b)
        # store the new color
        color_dict[hash_code] = new_col
        return new_col