import random


def InitializeClient(db_obj, client_id=None):
  """Initializes a test client.

  Args:
    db_obj: A database object.
    client_id: A specific client id to use for initialized client. If none is
      provided a randomly generated one is used.

  Returns:
    A client id for initialized client.
  """
  if client_id is None:
    client_id = "C."
    for _ in range(16):
      client_id += random.choice("0123456789abcdef")

  db_obj.WriteClientMetadata(client_id, fleetspeak_enabled=False)
  return client_id