TITLE: The existence of a polynomial of degree $n$ with $m$ real roots when $m\equiv n \pmod 2$.
QUESTION [9 upvotes]: I came across the following fact:

Let $m$ and $n$ be natural numbers such that $n\geqslant m$ and $m\equiv n \pmod 2$. Then, there exists an irreducible polynomial  $f\in\mathbb{Q}\left[X\right]$ of degree $n$  such that $f$ has exactly $m$ real roots.

I guess it is well known for algebraists. Unfortunately, I cannot find the proof of this anywhere and I do not know how to prove it. Could you help me?

REPLY [2 votes]: Suppose $f = \sum_{j=0}^n c_j X^j \in {\mathbb Z}[X]$ with degree $n$, having $m$ distinct real roots and $n-m$ distinct non-real complex roots. 
Let $C$ be a set consisting of disjoint small circles around each root of $f$.  By the argument principle, 
 if  $g \in {\mathbb Q}[X]$ of degree $n$ and $\max_{z \in C} |g(z)| < \min_{z \in C} |f(z)|$, then $f+g$ has exactly one root in each of the circles, and in particular has exactly $m$ real roots.  In particular, take $g = (X^n + p)/p^2$ where $p$ is a sufficiently large prime, and note that $f+g$ is irreducible in ${\mathbb Q}[X]$ by  Eisenstein's criterion.