function average = dice(diceSum, nTrials)

lengthSum = 0;
for trial = 1 : nTrials
    for rolls = 1 : 100000
        S = ceil(rand*6) + ceil(rand*6);
        if (S == diceSum) 
            lengthSum = lengthSum + rolls;
            break;
        end
    end
    if (rolls == 100000)
        fprintf('Error: sum %d not encountered\n', diceSum);
    end;
end

average = lengthSum / nTrials;
        