mercredi 10 octobre 2018

Python - Get random color, given a seed number as fast as possible

I need to find a random color, given a specific seed number - fast. given the same ID twice, should return the same color.

I did this:

def id_to_random_color(number):
    random_bytes = hashlib.sha1(bytes(number)).digest()
    return [int(random_bytes[-1]) / 255, int(random_bytes[-2]) / 255, int(random_bytes[-3]) / 255, 1.0]

The problem is that calculating the sha1 of numbers many times is very slow in total. (I'm using this function about 100k times)




Aucun commentaire:

Enregistrer un commentaire