import hashlib
import six


def get_text_sharder(num_shards):
  """Returns a deterministic string-sharding function."""
  def sharder(text):
    return int(hashlib.md5(six.ensure_binary(text, 'utf-8')).hexdigest(),
               16) % num_shards

  return sharder