# start with N = number of repetitions, n = number of courses # also start with pa = Pr(A), pb = Pr(B), pc = Pr(C) # grpts = rep(NA, times = n) GPA = rep(NA, times = N) GPmax = rep(NA, times = N) for (i in 1:N) { rand = runif(n,0,1) for (j in 1:n) { if (rand[j] < pa) {grpts[j] = 4} if ((rand[j] >= pa) & (rand[j] < pa+pb)) {grpts[j] = 3} if (rand[j] >= pa+pb) {grpts[j] = 2} } GPA[i] = mean(grpts) GPmax[i] = max(grpts) } hist(GPmax); table(GPmax) mean(GPmax); sd(GPmax) hist(GPA); table(GPA) mean(GPA); sd(GPA)