This paper introduces new efficient algorithms for two problems: sampling conditional on vertex degrees in unweighted graphs, and sampling conditional on vertex strengths in weighted graphs. The algorithms can sample conditional on the presence or absence of an arbitrary number of edges. The resulting conditional distributions provide the basis for exact tests. Existing samplers based on MCMC or sequential importance sampling are generally not scalable; their efficiency degrades in sparse graphs. MCMC methods usually require explicit computation of a Markov basis to navigate the complex state space; this is computationally intensive even for small graphs. We use state-dependent kernel selection to develop new MCMC samplers. These do not require a Markov basis, and are efficient both in sparse and dense graphs. The key idea is to intelligently select a Markov kernel on the basis of the current state of the chain. We apply our methods to testing hypotheses on a real network and contingency table. The algorithms appear orders of magnitude more efficient than existing methods in the test cases considered.