concept-collection / walnuts-interactive
walnuts-interactive / helpers / p_micro.m
7 lines · 184 BBlameHistoryRaw
1function j = p_micro(i)
2 weights = [2/3, 1/3, 0];
3 choices = [i, i+1, i+2];
4 cdf = cumsum(weights);
5 r = rand() * cdf(end);
6 j = choices(find(cdf >= r, 1, 'first'));
7end