Given the Hilbert function $u$ of a closed subscheme of a projective space over an infinite field $K$, let $m_u$ and $M_u$ be, respectively, the minimum and the maximum among all the Castelnuovo-Mumford regularities of schemes with Hilbert function $u$. I show that, for every integer $m$ such that $m_u leq m leq M_u$, there exists a scheme with Hilbert function $u$ and Castelnuovo-Mumford regularity $m$. As a consequence, the analogous algebraic result for an O-sequence $f$ and homogeneous polynomial ideals over $K$ with Hilbert function $f$ holds too. Although this result does not need any explicit computation, I also describe how to compute a scheme with the above requested properties. Precisely, I give a method to construct a strongly stable ideal defining such a scheme.