if you have duplicated numbers eg
8118, do you still want 24 combinations, as some will be duplicates of others.
anyway, to fgenerate all legal combinations, treat a 4 digit numbers as a 4-char string, just use an array of size 24 and populate the array by reordring the strings
by this pseudocode
for pos1=1 to 4
for pos2 = 2 to 4
for pos3 = 3 to 4
array( calcindex from pos1,pos2,pos3,pos4) = val(stringformed from pos1,pos2,pos3,pos4)
this will give you 4 combinations of pos1, 3 of pos2, 2 of pos3, ie 4*3*2(*1) combinations, or 24 in total
then finalvalue = array1,array2, array3, etc