from typing import Optional
import random


def random_product(
        *iterables,
        repeat: int = 1,
        rng: Optional[random.Random] = None,
):
    """

    >>> from random import Random
    >>> random = Random(1)
    >>> suits = 'CDHS'
    >>> ranks = list(range(2, 11)) + ['J', 'Q', 'K', 'A']
    >>> card = random_product(ranks, suits, rng=random)
    >>> card
    (4, 'C')
    >>> random_product(ranks, suits, repeat=5, rng=random)
    (6, 'C', 9, 'S', 9, 'S', 'A', 'D', 3, 'S')

    """
    choice = random.choice if rng is None else rng.choice
    space = [tuple(value) for value in iterables] * repeat
    return tuple(choice(item) for item in space)