Channel Coding and Lossy Source Coding Using a Constrained Random Number Generator