TITLE: Domain of a random variable - sample space or probability space?
QUESTION [5 upvotes]: In most probability theory texts you'll see a random variable definition that goes something like this:
A probability space is a triple $(\Omega, \mathcal{F}, P)$, a real valued random variable is a function $X:\Omega \rightarrow \mathbb{R}$
The computer scientist in my head can't get around what seems to be a type-error.  Is a random variable dependent on $P$ or not.  My intuition says it is, which is why we say things like 'uniformly distributed random variable', but in this case shouldn't a random variable be a function from the probability space, i.e. $X:(\Omega, \mathcal{F}, P) \rightarrow \mathbb{R}$.  In fact this is how it is defined in Wolframs mathworld.
Alternatively, one could imagine in a functional programming language a function which counts the number of heads from a set of coin tosses.  This function could be independent of whether or not the coin is fair or biased, etc, and hence in some way independent of $P$.
I understand some of this may be just for convenience when speaking, but this is how a random variable is rigorously defined, so I believe I must be missing something.  In other words, my question is, is a random variable associated with probabilities or independent of it.

REPLY [2 votes]: A random variable is technically independent of a probability space, except for its domain.
Your functional programming metaphor is correct: this is exactly how we think of randomness and random variables in advanced probability theory. In a pure functional programming language (e.g. Haskell), we can't have randomness because it's a "side effect". In mathematics, we can't have randomness because we can't model it logically (except to quantify it with measures).
In both functional programming and mathematics, because we can't have randomness in our programs/logic, we pull it out and confine it to a thing we call a random source/probability space, which we assume creates/quantifies randomness. This leaves our programs/logic pristine and pure, so we can continue to use our libraries/theorems without fear of them not working because of corruption from random effects.
Allow me to speak frankly: syntax like $X : (\Omega,\mathcal{F},P) \to \mathbb{R}$ is a poor attempt at connoting something about $X$. It's confusing to newcomers and so badly thought out that it even fails to typecheck, and we mathematicians should do better.
Here's something that might work for you. A measure-theoretic model of a random process is a possibly infinite tuple
$$(\Omega,\mathcal{F},P,X_1,X_2,...)$$
where $X_1 : \Omega \to \Omega_1$ and $X_2 : \Omega \to \Omega_2$ and so on, are random variables: deterministic functions of an assumed-random source $\Omega$ whose assumed randomness is quantified by $P$. Their distributions $P_1,P_2,...$ are defined by
$$P_n(A) = P(X_n^{-1}(A))$$
or the probability of all the outcomes $\omega \in \Omega$ for which $X_n(\omega)$ is an observable outcome in $A$.
Defining a measure-theoretic model keeps the probability space and random variables in one object. If you lean object-oriented, you can imagine that $X_n$ are public accessors that return random observable outcomes, $P_n$ are public accessors that return probabilities of observable outcomes, and everything else are private implementation details that are subject to change, as long as the observed distributions remain the same.