def ran_r(r, graph, cls=BinaryQuadraticModel, seed=None):
    """Generate an Ising model for a RANr problem.

    In RANr problems all linear biases are zero and quadratic values are uniformly
    selected integers between -r to r, excluding zero. This class of problems is relevant
    for binary quadratic models (BQM) with spin variables (Ising models).

    This generator of RANr problems follows the definition in [Kin2015]_\ .

    Args:
        r (int):
            Order of the RANr problem.

        graph (int/tuple[nodes, edges]/:obj:`~networkx.Graph`):
            The graph to build the BQM for. Either an
            integer n, interpreted as a complete graph of size n, or
            a nodes/edges pair, or a NetworkX graph.

        cls (:class:`.BinaryQuadraticModel`):
            Binary quadratic model class to build from.

        seed (int, optional, default=None):
            Random seed.

    Returns:
        :obj:`.BinaryQuadraticModel`.

    Examples:

    >>> import networkx as nx
    >>> K_7 = nx.complete_graph(7)
    >>> bqm = dimod.generators.random.ran_r(1, K_7)

    .. [Kin2015] James King, Sheir Yarkoni, Mayssam M. Nevisi, Jeremy P. Hilton,
        Catherine C. McGeoch. Benchmarking a quantum annealing processor with the
        time-to-target metric. https://arxiv.org/abs/1508.05087

    """
    if not isinstance(r, int):
        raise TypeError("r should be a positive integer")
    if r < 1:
        raise ValueError("r should be a positive integer")

    if seed is None:
        seed = numpy.random.randint(2**32, dtype=np.uint32)
    rnd = numpy.random.RandomState(seed)

    variables, edges = graph

    index = {v: idx for idx, v in enumerate(variables)}

    if edges:
        irow, icol = zip(*((index[u], index[v]) for u, v in edges))
    else:
        irow = icol = tuple()

    ldata = np.zeros(len(variables))

    rvals = np.empty(2*r)
    rvals[0:r] = range(-r, 0)
    rvals[r:] = range(1, r+1)
    qdata = rnd.choice(rvals, size=len(irow))

    offset = 0

    return cls.from_numpy_vectors(ldata, (irow, icol, qdata), offset, vartype='SPIN',
                                  variable_order=variables)
Generate an Ising model for a RANr problem.

    In RANr problems all linear biases are zero and quadratic values are uniformly
    selected integers between -r to r, excluding zero. This class of problems is relevant
    for binary quadratic models (BQM) with spin variables (Ising models).

    This generator of RANr problems follows the definition in [Kin2015]_\ .

    Args:
        r (int):
            Order of the RANr problem.

        graph (int/tuple[nodes, edges]/:obj:`~networkx.Graph`):
            The graph to build the BQM for. Either an
            integer n, interpreted as a complete graph of size n, or
            a nodes/edges pair, or a NetworkX graph.

        cls (:class:`.BinaryQuadraticModel`):
            Binary quadratic model class to build from.

        seed (int, optional, default=None):
            Random seed.

    Returns:
        :obj:`.BinaryQuadraticModel`.

    Examples:

    >>> import networkx as nx
    >>> K_7 = nx.complete_graph(7)
    >>> bqm = dimod.generators.random.ran_r(1, K_7)

    .. [Kin2015] James King, Sheir Yarkoni, Mayssam M. Nevisi, Jeremy P. Hilton,
        Catherine C. McGeoch. Benchmarking a quantum annealing processor with the
        time-to-target metric. https://arxiv.org/abs/1508.05087