Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Simple hash that is consistent across platforms, appropriate for proc-gen purposes (but not cryptographically secure or anything)
- /// </summary>
- /// <param name="text">the text to hash</param>
- /// <returns>the int hash of the string</returns>
- static public int HashString(string text)
- {
- /*unchecked
- {
- int hash = 23;
- foreach (char c in text)
- {
- hash = hash * 31 + c;
- }
- return hash;
- }*/
- // (this is the Knuth hash)
- System.UInt64 hashedValue = 3074457345618258791ul;
- for (int i = 0; i < text.Length; i++)
- {
- hashedValue += text[i];
- hashedValue *= 3074457345618258799ul;
- }
- return (int)(hashedValue >> 32);
- }
- /// <summary>
- /// Returns a hash string generated from the current date, to feed into the Gauntlet for a daily challenge
- /// </summary>
- /// <returns>A hash string to generate a daily challenge</returns>
- static public string DailyHashString()
- {
- System.Globalization.CultureInfo cInfo = new System.Globalization.CultureInfo("en-US");
- int w = cInfo.Calendar.GetWeekOfYear(System.DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday);
- int d = cInfo.Calendar.GetDayOfYear(System.DateTime.Now);
- int y = cInfo.Calendar.GetYear(System.DateTime.Now);
- return d.ToString(System.Globalization.CultureInfo.InvariantCulture) + w.ToString(System.Globalization.CultureInfo.InvariantCulture) + y.ToString(System.Globalization.CultureInfo.InvariantCulture);
- }
Advertisement
Add Comment
Please, Sign In to add comment