TITLE: Measurable function from $[0,1]$ to $[0,1]$, mapping each sub interval onto $[0,1]$
QUESTION [6 upvotes]: Could anybody give a hint me how to construct a measurable function $f:[0,1]\rightarrow [0,1]$ such that:
$$\forall_{0\leq a < b \leq 1}: f((a,b))=[0,1]$$
I tried to define a sequence of linear functions $g_n$ that would "vertically cover" more and more of $[0,1]$ like so:
$g_0(x)=x$
$g_1(x) = \begin{cases}2x \text{, for } x\in[0,\frac{1}{2}]\\
 2x-1 \text{, for } x\in[\frac{1}{2},1]\end{cases}$
$...$
$g_n(x) = \begin{cases}2^nx \text{, for } x\in[0,\frac{1}{2^n}]\\
 2^nx-1 \text{, for } x\in[\frac{1}{2^n},\frac{2}{2^n}]\\
...\\
2^nx - (2^n-1)\text{, for } x\in[\frac{2^n-1}{2^n},1]\end{cases}$
Then I hoped for such a sequence, of clearly measurable functions, to converge pointwise, so that I could define $f(x)=\lim_{n\rightarrow\infty}g_n(x)$. It seems however, that $g_n$ will not converge and I am stuck looking for a different sequence. Or perhaps my approach is flawed from the very beginning? I will be gratefull for any inights or suggestions.

REPLY [2 votes]: Let $I_1,I_2,I_3,\dots$ enumerate all subintervals of $[0,1]$ with rational endpoints. Construct a sequence $A_1,A_2,A_3,\dots$ of pairwise disjoint sets so that $A_n$ is similar to the Cantor set and $A_n\subseteq I_n$. For each $n$ define a continuous surjection $f_n:A_n\to[0,1]$. Define $f:[0,1]\to[0,1]$ so that $f(x)=f_n(x)$ if $x\in A_n$ and $f(x)=0$ if $x\in[0,1]\setminus\bigcup_nA_n$.
Then $f$ maps each subinterval of $[0,1]$ onto $[0,1]$ because each subinterval contains an $A_n$, and $f$ is Borel measurable because, for each closed set $S$, the set $f^{-1}(S)$ is the union of an $F_\sigma$ set and a $G_\delta$ set.
P.S. To define a continuous surjection from the Cantor set to $[0,1]$, note that each element of the Cantor set can be expressed uniquely in the form $\sum_{k=1}^\infty\frac{2a_k}{3^k}$ with $a_k\in\{0,1\}$, and that the map $\sum_{k=1}^\infty\frac{2a_k}{3^k}\mapsto\sum_{k=1}^\infty\frac{a_k}{2^k}$ is continuous.