import numpy as np
import random
import itertools
import colorsys
hue, saturation, value = np.arange(0.0,1,0.05), np.arange(0.3,1.01,0.345), np.arange(0.3,1.01,0.345)
rlist= [colorsys.hsv_to_rgb(hue, saturation, value) for hue, saturation, value in
itertools.product(random.sample(hue,len(hue)), random.sample(saturation, len(saturation)), random.sample(value, len(value)))]
print rlist
EDIT: random.sample from full population to avoid inplace separate shuffles
The version without itertools:
# without itertools
import numpy as np
import random
from pprint import pprint
import colorsys
hues, saturations, values = np.arange(0.0,1,0.05), np.arange(0.3,1.01,0.345), np.arange(0.3,1.01,0.345)
rlist= [colorsys.hsv_to_rgb(hue, saturation, value)
for hue in random.sample(hues,len(hues))
for saturation in random.sample(saturations, len(saturations))
for value in random.sample(values, len(values))]
pprint(rlist)
You can also include the definition of itertools.product from documentation (I did that in module called it.py in my server and used it instead of itertools):
product = None
from itertools import *
if not product:
def product(*args, **kwds):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = map(tuple, args) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]
for prod in result:
yield tuple(prod)
I use itertools normally as:
import itertools as it
But in the server it is replaced by
import it