Guest User

Untitled

a guest
May 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. /// <summary>
  2. /// Simple hash that is consistent across platforms, appropriate for proc-gen purposes (but not cryptographically secure or anything)
  3. /// </summary>
  4. /// <param name="text">the text to hash</param>
  5. /// <returns>the int hash of the string</returns>
  6. static public int HashString(string text)
  7. {
  8. /*unchecked
  9. {
  10. int hash = 23;
  11. foreach (char c in text)
  12. {
  13. hash = hash * 31 + c;
  14. }
  15. return hash;
  16. }*/
  17.  
  18. // (this is the Knuth hash)
  19. System.UInt64 hashedValue = 3074457345618258791ul;
  20. for (int i = 0; i < text.Length; i++)
  21. {
  22. hashedValue += text[i];
  23. hashedValue *= 3074457345618258799ul;
  24. }
  25.  
  26. return (int)(hashedValue >> 32);
  27. }
  28.  
  29. /// <summary>
  30. /// Returns a hash string generated from the current date, to feed into the Gauntlet for a daily challenge
  31. /// </summary>
  32. /// <returns>A hash string to generate a daily challenge</returns>
  33. static public string DailyHashString()
  34. {
  35. System.Globalization.CultureInfo cInfo = new System.Globalization.CultureInfo("en-US");
  36.  
  37. int w = cInfo.Calendar.GetWeekOfYear(System.DateTime.Now, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Monday);
  38. int d = cInfo.Calendar.GetDayOfYear(System.DateTime.Now);
  39. int y = cInfo.Calendar.GetYear(System.DateTime.Now);
  40.  
  41. return d.ToString(System.Globalization.CultureInfo.InvariantCulture) + w.ToString(System.Globalization.CultureInfo.InvariantCulture) + y.ToString(System.Globalization.CultureInfo.InvariantCulture);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment