How to hash a string to integer with a range in PHP

Here is a simple way in PHP to hash a string to an integer. That is, mapping a string to a specific number.

This function has a default range of 100. (That means the outcome can be 0 – 99 )

Example Usage

Simple load-balancing depends on the username

Extend Reading

1. This stackoverflow post is related to how to hash a string to integer using md5, but I found the resulting integer is too large for my practical use
http://stackoverflow.com/questions/965304/php-hash-form-string-to-integer

Share your thoughts