You have a fair generator with one number of outcomes and need a fair generator with another. Each function receives the base generator's draws as a list of integers and must return the derived samples in order, consuming the draws left to right and stopping when the draws run out (an incomplete final attempt is discarded).
rand5_from_rand7(draws)
draws are uniform on {1, ..., 7}. Accept a draw if it is at most 5 and emit it; otherwise discard it and move on. Return the list of accepted values.rand7_from_rand5(draws)
draws are uniform on {1, ..., 5}. Take draws in pairs (a, b) and form v = 5 * (a - 1) + b, which is uniform on {1, ..., 25}. Accept when v <= 21 and emit (v - 1) % 7 + 1; otherwise discard the pair. Return the list of emitted values.expected_base_draws(n, m, k)
k draws from an n-sided generator to form a uniform value on n**k outcomes, and accepts it if it falls in the largest multiple of m that fits. Return the expected number of base draws per emitted sample, rounded to 4 decimals.(largest multiple of m that fits) / n**k; the number of attempts is geometric.