I want to create a matrix showing all possible combinations of tossing n independent dice rolls, except that dice is not always 6-sided.
e.g. I want to create matrix res
res = [1,1,1; 1,1,2; 1,2,1; 1,2,2; 2,1,1; 2,1,2; 2,2,1; 2,2,2];
using a vector v = [2,2,2]. Basically vector v specifies the number and size of each dice. Is there a fast way to iterate this without using for loop? I know if the dice size is constant I can use:
res = dec2base(0:dice_size^n-1,dice_size) - '0'; res = res + 1;
But I am stuck when each dice has different sizes.
Best Answer