Skip to content

Instantly share code, notes, and snippets.

Created June 7, 2013 17:46
Show Gist options
  • Save anonymous/5731032 to your computer and use it in GitHub Desktop.
Save anonymous/5731032 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
namespace TinkerWorX.Legeria.Shared
{
public static class Utilities
{
public static readonly Random Random = new Random();
public static Int32 Remainder(Int32 a, Int32 b)
{
return (a % b + b) % b;
}
public static void Swap<T>(ref T a, ref T b)
{
var t = a;
a = b;
b = t;
}
public static Int32 RandomFromCoords(Int32 x, Int32 y, Int32 minValue, Int32 maxValue)
{
return (new Random((51 + x) * 51 + y)).Next(minValue, maxValue);
}
/*
public static Int32 RandomFromCoords(Int32 x, Int32 y, Int32 minValue, Int32 maxValue)
{
// Random Number Generator voodoo found at:
// http://en.wikipedia.org/wiki/Random_number_generation#Computational_methods
var z = 36969 * (x & 65535) + (x >> 16);
var w = 18000 * (y & 65535) + (y >> 16);
var dn = ((z << 16) + w) / (Double)Int32.MaxValue;
return (Int32)(Math.Floor(dn * (maxValue - minValue)) + minValue);
}
*/
public static String MD5(String input)
{
return MD5Core.GetHash(input).Aggregate(String.Empty, (current, character) => current + character.ToString("x2"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment