Domain of a random variable - sample space or probability space? 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.  
 A: Your observation is reasonable, but your suggested cure for the problem, making $(\Omega,\mathcal F,P)$ the domain of $X$, won't work because the domain of a function needs to be a set (or a type or something like that).  My impression is that, when people refer to a function $X:\Omega\to\mathbb R$ as a random variable, they always do so in the context of a probability-space structure ($\mathcal F$ and $P$) on $\Omega$.  If no such structure is given, then I wouldn't call $X$ a random variable. And if there is uncertainty about which structure is intended, then, as you said, notions like "distribution" of $X$ will not be well-defined.
If I had to formalize the notion of random variable, in Bourbaki style, I would probably say that a random variable is a pair consisting of a probability space $(\Omega,\mathcal F,P)$ together with a function $X:\Omega\to\mathbb R$.  As with many mathematical concepts, one often omits mentioning part of an entity (in this case the probability space) when it is understood from the context.
A: 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.
A: A random variable $X$ is a measurable map from the probability space $(\Omega, \mathcal{F}, P)$ to another measure space $(S, \mathcal{S})$ (usually $(\mathbb{R}, \mathcal{B}(\mathbb{R}))$. It is not just a function between $\Omega$ and $S$ - the measurability of the map (which intrinsically depends on the measure spaces $(\Omega, \mathcal{F}, P)$ and $(S, \mathcal{S})$) is a key part of the definition of the random variable $X$. 
It is just cumbersome to write out the entire measure space every time, so we just write $X: \Omega \to S$ and keep the measures and $\sigma$-fields implicit. 
