Random Variable is a FUNCTION?!

I can’t help but to remind myself about the word-for-word definition of random variables: a random variable is a real-valued FUNCTION that has a property that for every Borel subset B of R, subset of omega is in the sigma-algebra. I had a really hard time digesting that a random variable is a function—in math, function was something that represented relationship between variables. If F(X) = 2X, I can clearly see that F is a function, a "black box" that takes an input and returns twice of the input. A random variable X, let's say number of heads in finite coin-tossing sequence, is ALSO a function. I guess in this case, the input is the "coin-tossing" and the return value is "the number of heads". I just wanted to reiterate that random variable is a FUNCTION before I go to bed today.