def get_stream_id_for_topic(topic_name, rng=2):
    """To distribute load, all the topics are not in the same stream. Each topic named is hashed
    to obtain an id which is in turn the name of the stream.
    This uses the djb2 algorithm, as described here
    https://mapr.com/docs/60/AdministratorGuide/spyglass-on-streams.html"""
    if rng == 1:
        return 0

    h = 5381
    for c in topic_name:
        h = ((h << 5) + h) + ord(c)
    return abs(h % rng)