import random


def _course_cmp(x, y):
  """A comparator function for courses.

  Redacted courses are randomly sorted towards the bottom of the list. Otherwise
  the original ordering is preserved.

  Args:
    x: The first course to be compared.
    y: The second course to be compared.

  Returns:
    -1 if x is 'Redacted,' 1 if y is 'Redacted,' 0 otherwise.
  """
  if x.code == 'Redacted' and y.code == 'Redacted':
    return random.randint(-1, 1)
  elif x.code == 'Redacted':
    return 1
  elif y.code == 'Redacted':
    return -1

  return 0