# Definition of a random sequence of random variables

The following is a passage from Durrett's book on probability.

''If $$X_n \in \{0,1\}$$ are independent with $$P(X_n=1)=a_n \to 0$$ and $$\sum a_n = \infty$$, then $$X_n \to 0$$ in probability, but if we let $$N(n)=\text{inf}\{m\geq n: X_m=1\}$$, then $$X_{N(n)}=1$$ a.s.''

The statement itself is not important, but I'm having trouble understanding the sequence $$X_{N(n)}$$ in a rigorous way. Can someone explain how the random variables $$\{X_{N(n)}\}$$ look like as measurable functions and also as a subsequence of the original sequence $$\{X_n\}$$?

Recall that $$X_n$$ is just a measurable function on some probability space (about which we usually don't care). But let us fix this probability space $$(\Omega, \mathcal{F}, \mathbb{P}).$$ So $$X_n:(\Omega, \mathcal{F}, \mathbb{P})\to \{0, 1\}$$ is a measurable function with some properties (but I will ignore them as you said the exact statement is not important).
Now if you have another measurable function $$N:(\Omega, \mathcal{F}, \mathbb{P})\to \mathbb{N},$$ then you can define a compostie function say $$Y:(\Omega, \mathcal{F}, \mathbb{P})\to \{0, 1\}$$ by $$Y(\omega)=X_{N(\omega)}(\omega).$$ This is what we are talking about.
Probabilistically, think of the situation as follows: Think of $$X_n$$ as being representing head/tail in a coin toss. But let us say you are interested in some particular $$X_n,$$ for example, you might be interested in what happens in the $$10$$th toss, that is, you are interested in $$X_{10}.$$ This is simple. But you might be interested in something more complicated. Imagine that you are playing a game where you win if you see $$5$$ consecutive zeroes and then $$1.$$ Naturally, if you look at the time of your first win, it is a random time, you can call it $$N.$$