def generate_pairwise(params, n_comparisons=<NUM_LIT:10>):
n = len(params)<EOL>items = tuple(range(n))<EOL>params = np.asarray(params)<EOL>data = list()<EOL>for _ in range(n_comparisons):<EOL><INDENT>a, b = random.sample(items, <NUM_LIT:2>)<EOL>if compare((a, b), params) == a:<EOL><INDENT>data.append((a, b))<EOL><DEDENT>else:<EOL><INDENT>data.append((b, a))<EOL><DEDENT><DEDENT>return tuple(data)<EOL>
Generate pairwise comparisons from a Bradley--Terry model.

    This function samples comparisons pairs independently and uniformly at
    random over the ``len(params)`` choose 2 possibilities, and samples the
    corresponding comparison outcomes from a Bradley--Terry model parametrized
    by ``params``.

    Parameters
    ----------
    params : array_like
        Model parameters.
    n_comparisons : int
        Number of comparisons to be returned.

    Returns
    -------
    data : list of (int, int)
       Pairwise-comparison samples (see :ref:`data-pairwise`).