  Aims: To provide a significantly improved probability distribution for the
H-test for periodicity in X-ray and $\gamma$-ray arrival times, which is
already extensively used by the $\gamma$-ray pulsar community. Also, to obtain
an analytical probability distribution for stacked test statistics in the case
of a search for pulsed emission from an ensemble of pulsars where the
significance per pulsar is relatively low, making individual detections
insignificant on their own. This information is timely given the recent rapid
discovery of new pulsars with the Fermi-LAT t $\gamma$-ray telescope. Methods:
Approximately $10^{14}$ realisations of the H-statistic ($H$) for random
(white) noise is calculated from a random number generator for which the
repitition cycle is $\gg 10^{14}$. From these numbers the probability
distribution $P(>H)$ is calculated. Results: The distribution of $H$ is is
found to be exponential with parameter $\lambda=0.4$ so that the cumulative
probability distribution $P(>H)=\exp{(-\lambda H)}$. If we stack independent
values for $H$, the sum of $K$ such values would follow the Erlang-K
distribution with parameter $\lambda$ for which the cumulative probability
distribution is also a simple analytical expression. Conclusion: Searches for
weak pulsars with unknown pulse profile shapes in the Fermi-LAT, Agile or other
X-ray data bases should benefit from the {\it H-test} since it is known to be
powerful against a broad range of pulse profiles, which introduces only a
single statistical trial if only the {\it H-test} is used. The new probability
distribution presented here favours the detection of weaker pulsars in terms of
an improved sensitivity relative to the previously known distribution.
