In a recent work [Phys. Rev. E 97, 030202(R) (2018)10.1103/PhysRevE.97.030202], Sakhr and Nieminen (SN) solved a hypothesis formulated two decades ago, according to which the local box-counting dimension D_{box}(r) of a given energy spectrum, or more generally of a discrete set, should exclusively depend on the nearest-neighbor spacing distribution P(s) of the spectrum (set). SN found analytically this dependence, which led them to obtain closed formulas for the local box-counting dimension of Poisson spectra and of spectra belonging to Gaussian orthogonal, unitary, and symplectic ensembles. Here, first, we present a different derivation of the equation establishing the connection of D_{box}(r) and P(s) using the concept of surrogate spectrum. Although our equation is formally different to the SN result, we prove that both are equivalent. Second, we apply our equation to solve the inverse problem of determining the functional form of P(s) for spectra with real fractal structure and constant box-counting dimension D_{box}, and we find that P(s) should behave as a power-law of the spacing, with an exponent given by -(1+D_{box}). Finally, we present four applications or consequences of this last result: First, we provide a simple algorithm able to generate random fractal spectra with prescribed and constant D_{box}. Second, we calculate D_{box} for the sets given by the zeros of fractional Brownian motions, whose P(s) is known to have a power-law tail. Third, we also study D_{box}(r) for the zeros of fractional Gaussian noises, whose P(s) in known to present fat (but not power-law) tails, and that could be misinterpreted as real fractals. And finally, we present the calculation of D_{box} for the spectra of Fibonacci Hamiltonians, known to have fractal properties, simply by fitting their corresponding P(s) to a power-law without the need of applying a box-counting algorithm.