% roll dice example % Constants: MINROLLS = 0; % min number of rolls MAXROLLS = 1000; % max number of rolls MINSIZE = 4; % min size of a die MAXSIZE = 100; % max size of a die % Variables: dieSize = readInt(MINSIZE,MAXSIZE,'Enter size of die [4-100]: '); rolls = readInt(MINROLLS,MAXROLLS,'Enter number of rolls to do [0-1000]: '); counts = zeros(dieSize,1); % counts of each die roll so far (nothing) % Roll the die and count how often each side appears: for currentRoll=0:rolls dieRoll = randInt(1,dieSize); % roll die counts(dieRoll) = counts(dieRoll)+1; % add that roll to its count end % Report the frequences: 100*counts/rolls