Question: What range of numbers $[2, X]$ should I search, to be absolutely sure that I would get exactly or more than $N$ prime numbers within that range? Any formula for $X$?

Answer: 
Since $\pi(x)\sim\frac{x}{\log x}$ by the PNT, $p\_n$ behaves like $n\log n$. You may use Chebyshev's weak version $$C\_1\frac{x}{\log x}\leq \pi(x)\leq C\_2\frac{x}{\log x}$$
to deduce explicit (enough) bounds for $p\_n$. 

Anyway, unless $n$ is extremely small, there are at least $n$ primes in the range $[2,n\log^2(n)]$.
Rosser and Schoenfeld proved that for $X \ge 17$ there are at least $N$ primes less than or equal to $\dfrac X {\ln X}$. So, choose $X$ so that $\dfrac X {\ln X} \ge N$.