Random variable iff constant on each element of a partition 
Let $A=\{A_1,\ldots,A_n\}$ be a partition of a set $\Omega$ and let $F=\sigma(A)$.
Prove that $X : \Omega \to \Bbb R$ is a random variable if and only if it is constant on each element of the partition.

I am trying to do the proof by contradiction but it seems the wrong way.
Any hint?
Thanks in advance for your help.
 A: In order to be a random variable, $X$ needs to be a measurable function (wrt the $\sigma$-algebra). Therefore it is convenient first to analyze such $\sigma$-algebra.
The $\sigma$-algebra
Let $\mathcal A =\sigma\{A_1,\ldots A_n\}$. By definition, $\mathcal A$ contains the whole space $\Omega$ and is closed under (countable) unions, i.e. whenever you pick some of its sets (countably-many) their union still belongs to $\mathcal A$. Therefore, $\mathcal A$ surely contains all the possible unions of "cells" $A_i$, that is
$$
\mathcal B ~:=~ \Big\{A_{i_1}\cup A_{i_2}\ldots\cup A_{i_k}~:~0\leq k\leq n, ~1\leq i_1<i_2\ldots<i_k\leq n\Big\}
\quad\subseteq\quad
\mathcal A
$$
It is handy to define $\mathcal B$ in words as the set of all the possible unions of cells.
We just have to show that $\mathcal B$ is itself a $\sigma$-algebra, i.e. that the other inclusion $\mathcal B\supseteq\mathcal A$ holds too and so that $\mathcal A=\mathcal B$. To prove this we just have to check that $\mathcal B$ contains all the sets $A_j$ and that it satisfies all the properties of a $\sigma$-algebra:


*

*$\color{red}{A_j\in\mathcal B~~\forall j.}\quad$This is straightforward, isn't it? In our notation, the cell $A_j$ corresponds to the choice $k=1$ and $i_1=j$.

*$\color{red}{\Omega\in\mathcal B.}\quad$The whole set $\Omega$ corresponds to the choice $k=n$ and $i_j=j$ $~(j=1\ldots n)$ since indeed $\Omega=A_1\cup A_2\ldots\cup A_n$.

*$\color{red}{\mathcal B~\text{is closed under (countable) union}.}\quad$This again is straightforward, since "any union of unions of cells" is again a "union of cells". Besides note that we could also drop the adjective "countable" since $\mathcal B$ is finite (it has exactly $2^n$ elements).

*$\color{red}{\mathcal B~\text{is closed under complementation.}}\quad$Let $B\in\mathcal B$, then by definition $B$ is a "union of cells": $B=A_{i_1}\cup A_{i_2}\ldots\cup A_{i_k}$. Its complement is simply the union of all the other cells, that is$$B^{\sf C}=\bigcup_{\substack{j=1\ldots n\\j\notin\{i_1\ldots i_k\}}}A_j$$This applies to the case $B=\Omega$ too, whose complement is the empty set $\emptyset$ which corresponds to the choice $k=0$ in our notation.


When is $X$ measurable?
For $X:(\Omega,\mathcal A)\rightarrow \mathbb R$ to be $\mathcal A$-measurable, any preimage of measurable sets in $\mathbb R$ has to belong to $\mathcal A$. Since the singletons $\{c\}\subset\mathbb R$ are measurable $\forall c\in\mathbb R$, then
$$
X^{-1}(\{c\}) \in \mathcal A
\quad\forall c\in\mathbb R
$$
This means that $X^{-1}(\{c\})$ is either empty or the union of some of the cells $A_1\ldots A_n$, say $X^{-1}(\{c\})=A_{i_1}\cup A_{i_2}\ldots A_{i_k}$. This means that $X$ in constant on $A_{i_1}$, $A_{i_2}$ ... and $A_{i_k}$ (since on those cells it is constantly equal to $c$).
If you want to use contradiction, assume that $X$ is not constant over a certain cell, say $A_i$. Therefore there exists a value $c\in\mathbb R$ s.t. $A_i\not\subseteq X^{-1}(\{c\})$ and $A_i\cap X^{-1}(\{c\})\neq\emptyset$: this means that $A_i$ is only "partially included" in the preimage of $\{c\}$, and consequently it cannot belong to $\mathcal A$ (it is not a "union of entire cells").
