TITLE: Average Frequency of 1's in an Infinite Binary Sequences Can be Anything Between 0 and 1
QUESTION [10 upvotes]: The following question came up when me and a friend of mine were discussing some basic things about probability:
Let $p$ be a real number in $[0,1]$.
Does there exist a sequence $(x_1, x_2, x_3, \ldots)$ with each $x_i$ being either $0$ or $1$, such that
$$
\lim_{n\to \infty} \frac{f(n)}{n} =p
$$
where $f(n)= x_1+x_2+\cdots+x_n$, that is, $f(n)$ is the number of times $1$ has appeared in the first $n$ slots. 
Motivation: Consider a coin which may or may not be fair, and say the probability of "heads" showing up is $p$.
Suppose we want to have a machine which simulates this coin.
That is, we want to have a machine which shows either "H" or "T" every second ('second' here is a unit of time) on its screen.
If the machine properly simulates the coin, then we must have the average frequency of "H" occuring is $p$.

REPLY [3 votes]: Let
$$x_i=1\iff((i-1)p,\ ip]\cap\mathbb N\ne\emptyset,$$
otherwise $x_i=0.$ Observe that
$$\frac{x_1+\cdots+x_n}n=\frac{\lfloor np\rfloor}n,$$
$$p-\frac1n=\frac{np-1}n\lt\frac{\lfloor np\rfloor}n\le\frac{np}n=p,$$
whence
$$p-\frac1n\lt\frac{x_1+\cdots+x_n}n\le p.$$