  This paper introduces an open-ended sequential algorithm for computing the
p-value of a test using Monte Carlo simulation. It guarantees that the
resampling risk, the probability of a different decision than the one based on
the theoretical p-value, is uniformly bounded by an arbitrarily small constant.
Previously suggested sequential or non-sequential algorithms, using a bounded
sample size, do not have this property. Although the algorithm is open-ended,
the expected number of steps is finite, except when the p-value is on the
threshold between rejecting and not rejecting. The algorithm is suitable as
standard for implementing tests that require (re-)sampling. It can also be used
in other situations: to check whether a test is conservative, iteratively to
implement double bootstrap tests, and to determine the sample size required for
a certain power.
