Week 1: Sample Function Output wrong

I’m getting wrong results for the Sample function as given below what could be the cause?

list of sampled indices:
[11, 23, 16, 15, 1, 23, 23, 13, 17, 17, 0]
list of sampled characters:
[‘k’, ‘w’, ‘p’, ‘o’, ‘a’, ‘w’, ‘w’, ‘m’, ‘q’, ‘q’, ‘\n’]

Figured out the reason, my z calculation was wrong (used a_prev instead of a).
Now I’m getting correct results.