def METHOD_NAME(states, weight_indices, index_to_weight, size=1, seed=None):
    """
    Generate a sample of given size, given a probability mass function.
    Parameters
    ----------
    states: numpy.array
        Array of all possible states that the random variable can take.
    weight_indices: numpy.array
        Array with the weight indices for each sample
    index_to_weight: numpy.array
        Array mapping each weight index to a specific weight
    size: int
        Size of the sample to be generated.
    seed: int (default: None)
        If a value is provided, sets the seed for numpy.random.
    Returns
    -------
    samples: numpy.array
        Array of values of the random variable sampled from the given PMF.
    Example
    -------
    >>> import numpy as np
    >>> from pgmpy.utils.mathext import sample_discrete
    >>> values = np.array(['v_0', 'v_1', 'v_2'])
    >>> probabilities = np.array([0.2, 0.5, 0.3])
    >>> sample_discrete(values, probabilities, 10, seed=0).tolist()
    ['v_1', 'v_2', 'v_1', 'v_1', 'v_1', 'v_1', 'v_1', 'v_2', 'v_2', 'v_1']
    """
    if seed is not None:
        np.random.seed(seed)
    # TODO: Remove this conversion and find a way to do this natively in torch.
    states = np.array(states)
    weight_indices = compat_fns.to_numpy(weight_indices)
    index_to_weight = {
        key: compat_fns.to_numpy(value) for key, value in index_to_weight.items()
    }
    size = int(size)
    samples = np.zeros(size, dtype=int)
    unique_weight_indices, counts = np.unique(weight_indices, return_counts=True)
    for weight_size, weight_index in zip(counts, unique_weight_indices):
        samples[(weight_indices == weight_index)] = np.random.choice(
            states, size=weight_size, p=_adjusted_weights(index_to_weight[weight_index])
        )
    return samples