def random_xorsat(num_variables, num_clauses, vartype=dimod.BINARY, satisfiable=True):
if num_variables < <NUM_LIT:3>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if num_clauses > <NUM_LIT:8> * _nchoosek(num_variables, <NUM_LIT:3>):  <EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>csp = ConstraintSatisfactionProblem(vartype)<EOL>variables = list(range(num_variables))<EOL>constraints = set()<EOL>if satisfiable:<EOL><INDENT>values = tuple(vartype.value)<EOL>planted_solution = {v: choice(values) for v in variables}<EOL>configurations = [(<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>), (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:1>), (<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:1>), (<NUM_LIT:1>, <NUM_LIT:1>, <NUM_LIT:0>)]<EOL>while len(constraints) < num_clauses:<EOL><INDENT>x, y, z = sample(variables, <NUM_LIT:3>)<EOL>if y > x:<EOL><INDENT>x, y = y, x<EOL><DEDENT>const = xor_gate([x, y, z], vartype=vartype)<EOL>config = choice(configurations)<EOL>for idx, v in enumerate(const.variables):<EOL><INDENT>if config[idx] != (planted_solution[v] > <NUM_LIT:0>):<EOL><INDENT>const.flip_variable(v)<EOL><DEDENT><DEDENT>assert const.check(planted_solution)<EOL>constraints.add(const)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>while len(constraints) < num_clauses:<EOL><INDENT>x, y, z = sample(variables, <NUM_LIT:3>)<EOL>if y > x:<EOL><INDENT>x, y = y, x<EOL><DEDENT>const = xor_gate([x, y, z], vartype=vartype)<EOL>for idx, v in enumerate(const.variables):<EOL><INDENT>if random() > <NUM_LIT>:<EOL><INDENT>const.flip_variable(v)<EOL><DEDENT><DEDENT>assert const.check(planted_solution)<EOL>constraints.add(const)<EOL><DEDENT><DEDENT>for const in constraints:<EOL><INDENT>csp.add_constraint(const)<EOL><DEDENT>for v in variables:<EOL><INDENT>csp.add_variable(v)<EOL><DEDENT>return csp<EOL>
Random XOR constraint satisfaction problem.

    Args:
        num_variables (integer): Number of variables (at least three).
        num_clauses (integer): Number of constraints that together constitute the
            constraint satisfaction problem.
        vartype (Vartype, optional, default='BINARY'): Variable type. Accepted
            input values:

            * Vartype.SPIN, 'SPIN', {-1, 1}
            * Vartype.BINARY, 'BINARY', {0, 1}
        satisfiable (bool, optional, default=True): True if the CSP can be satisfied.

    Returns:
        CSP (:obj:`.ConstraintSatisfactionProblem`): CSP that is satisfied when its variables
        are assigned values that satisfy a XOR satisfiability problem.

    Examples:
        This example creates a CSP with 5 variables and two random constraints and checks
        whether a particular assignment of variables satisifies it.

        >>> import dwavebinarycsp
        >>> import dwavebinarycsp.factories as sat
        >>> csp = sat.random_xorsat(5, 2)
        >>> csp.constraints    # doctest: +SKIP
        [Constraint.from_configurations(frozenset({(1, 0, 0), (1, 1, 1), (0, 1, 0), (0, 0, 1)}), (4, 3, 0),
         Vartype.BINARY, name='XOR (0 flipped)'),
         Constraint.from_configurations(frozenset({(1, 1, 0), (0, 1, 1), (0, 0, 0), (1, 0, 1)}), (2, 0, 4),
         Vartype.BINARY, name='XOR (2 flipped) (0 flipped)')]
        >>> csp.check({0: 1, 1: 0, 2: 0, 3: 1, 4: 1})       # doctest: +SKIP
        True