There are $N$ optimization variables, $v_1,v_2,\cdots,v_N$. and $v_n\in{0,1,2,3,\cdots,K}$.
Let $N=10$ and $K=5$.
How can I generate all the possible combinations?
For example, the first combination is $[0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0\hspace{1mm} 0]$
The last combination is $[5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5\hspace{1mm} 5]$
${\bf EDIT}$: Then I need to filter out the tuples that do not give sum (of elements) exactly equal to 5.
Using
IntegerPartitions[5,{10},range[0,5]] is giving me some of the possible combinations, not all!
For example, its giving {1,1,1,1,1,0,0,0,0,0} as one of the candidate, but does not give {0,0,0,0,0,1,1,1,1,1} as another candidate.
Tuples[Range[0,5],10]
$\endgroup$IntegerPartitions
more or less as in here. For example, tryTable[IntegerPartitions[sum, {10}, Range[0, 5]], {sum, 6, 5 10}]
. I think this almost has an answer in the linked question already. $\endgroup$