
namespace SoMRandomizer.util.rng
{
    /// <summary>
    /// Hash a string in a way that is consistent across platforms, which string.HashCode() apparently is not.
    /// </summary>
    /// 
    /// <remarks>Author: Unknown - this came off the internet somewhere</remarks>
    public class HashcodeUtil
    {
        public static int GetDeterministicHashCode(string str)
        {
            int hash1 = (5381 << 16) + 5381;
            int hash2 = hash1;

            for (int i = 0; i < str.Length; i += 2)
            {
                hash1 = ((hash1 << 5) + hash1) ^ str[i];
                if (i == str.Length - 1)
                    break;
                hash2 = ((hash2 << 5) + hash2) ^ str[i + 1];
            }

            return hash1 + (hash2 * 1566083941);
        }
    }
}
