Answer edited according to new question
You could use list comprehensions, which are reasonably fast. The following code only took a few seconds on my PC. I used John Coleman's idea to first find the possible combinations of sums per group. I also used integers rather than floats. To transform the solutions back to the problem as stated in the question, divide every list value by 10.
from itertools import product
A = range(8) # 1 value from this group
B = range(7) # 5 values from this group (with replacement)
C = range(10) # 5 values from this group (with replacement)
D = range(2) # 2 values from this group (with replacement)
# use John Coleman's idea:
# first find all possible combinations of sums per group
groupsums = [sums for sums in product(A, B, C, D) if sum(sums) == 10]
print(len(groupsums)) # -> 95
def picks(maxi, n):
"""Returns list of combinations of n integers <= maxi
that sum to maxi."""
return [combi for combi in product(range(maxi + 1), repeat=n)
if sum(combi) == maxi]
# make list of lists that each have 13 items from the above ranges,
# with constraints as stated in the question
samples = [[a, b0, b1, b2, b3, b4, c0, c1, c2, c3, c4, d0, d1]
for a, b, c, d in groupsums
for b0, b1, b2, b3, b4 in picks(b, 5)
for c0, c1, c2, c3, c4 in picks(c, 5)
for d0, d1 in picks(d, 2)]
# show the first 5 and last 5 results
for i in range(5):
print(samples[i])
print('...')
for i in range(1, 6):
print(samples[-i])
# show the number of solutions
print(len(samples))
95
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 0, 1]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 1, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 0, 1]
...
[7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[7, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[7, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[7, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
[7, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
313027