import sympy
import six
import random


def _split_factors(integer):
  """Randomly factors integer into product of two integers."""
  assert integer.is_Integer
  if integer == 0:
    return [1, 0]
  # Gives dict of form {factor: multiplicity}
  factors = sympy.factorint(integer)
  left = sympy.Integer(1)
  right = sympy.Integer(1)
  for factor, mult in six.iteritems(factors):
    left_mult = random.randint(0, mult)
    right_mult = mult - left_mult
    left *= factor ** left_mult
    right *= factor ** right_mult
  return left, right