import math
import string
import itertools


def generate_shard_names(num_shards):
  """Generates strings of of ASCII sequence permutations for naming shards.

  Usage:
    >>> generate_shard_names(3)
    ['abc', 'acb', 'bac']
  Args:
    num_shards: The number of shard names to generate.
  Returns:
    A list of generally monotonically-increasing ASCII sequence strings.
  """
  # Find a number of permutations that is larger than the number of shards
  # requested. The number of ordered permutations is just a factorial.
  permutation_length = None
  for i in range(1, 10):  # Support num_shards from 1 to 362880.
    if math.factorial(i) > num_shards:
      permutation_length = i
      break
  # Generate permutations of ASCII letters, then trim it to num_shards.
  permutable_characters = string.ascii_letters[:permutation_length]
  tags = [''.join(p) for p in itertools.permutations(permutable_characters)]
  return tags[:num_shards]